Integrate Flask-JSGlue on a socketized Flask-SocketIO application

核能气质少年 提交于 2019-12-11 19:17:29

问题


Case 1

Suppose you have a Python Flask application and you want to socketize it - you do the standard:

app = Flask("MyApp")
socketio = SocketIO(app)

Case 2

Suppose you have a Python Flask application and you want to integrate Flask-JSGlue - https://pypi.org/project/Flask-JSGlue/ - you do the standard:

jsglue = JSGlue()
app = Flask("MyApp") 
jsglue.init_app(app)

Case 3 (Question)

Suppose now you want to integrate Flask-JSGlue on a socketized app - how would you go with this?

I'm trying to understand how can I merge Case 1 and Case 2 in order to obtain a socketized Flask app that integrates Flask-JSGlue.

What I've tried

As a first try I tried doing:

jsglue = JSGlue()
app = Flask("MyApp")
socketio = SocketIO(app)
jsglue.init_app(socketio)

But this results in the following error:

jsglue.init_app(socketio) File "C:\Python27\lib\site-packages\flask_jsglue.py", line 31, in init_app @app.route(JSGLUE_JS_PATH) AttributeError: 'SocketIO' object has no attribute 'route'

As a second try, as stated also in the comments, I tried doing:

jsglue = JSGlue()
app = Flask("MyApp")
socketio = SocketIO(app)
jsglue.init_app(app)

Doing so results in program being executed but socketized functions becoming totally unresponsive.

If anybody knows how to do this, that would be great

来源:https://stackoverflow.com/questions/54310058/integrate-flask-jsglue-on-a-socketized-flask-socketio-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!