我的旧代码,我使用werkzeug run_simple来运行应用程序。现在,我需要使用socketio,如何将run_simple()更改为socketio.run()。
我的旧代码:
from werkzeug.serving import run_simple
from werkzeug.wsgi import DispatcherMiddleware
from admin import api, frontend
application = DispatcherMiddleware(frontend.create_app(), {
'/api': api.create_app()
})
if __name__ == '__main__':
run_simple('0.0.0.0', 5000, application, use_reloader=True, use_debugger=False)
我试过了:
from werkzeug.serving import run_simple
from werkzeug.wsgi import DispatcherMiddleware
from flask.ext.socketio import SocketIO
from admin import api, frontend
app = frontend.create_app()
application = DispatcherMiddleware(frontend.create_app(), {
'/api': api.create_app()
})
socketio = SocketIO(app)
if __name__ == '__main__':
# run_simple('0.0.0.0', 5000, application, use_reloader=True, use_debugger=False)
socketio.run(app, host='0.0.0.0', port=5000, use_reloader=True, use_debugger=False)
但它没有用。任何人都可以帮助我!
答案 0 :(得分:0)
通过包装和替换http://electron.atom.io/docs/faq/所描述的Flask应用wsgi_app
属性,可以实现这一点。
app = frontend.create_app()
app.wsgi_app = DispatcherMiddleware(app.wsgi_app, {
'/api': api.create_app()
})
socketio = SocketIO(app)
if __name__ == "__main__":
socketio.run(app, host='0.0.0.0', port=5000, use_reloader=True, use_debugger=False)