我已经安装了Flask-Login和Flask-Sockets。它们都可以正常工作,但是当尝试获取当前用户(使用g.user)时,会出现AttributeError:'_AppCtxGlobals' object has no attribute 'user'
错误。
@sockets.route('/echo')
def echo_socket(ws):
with app.app_context():
user = current_user #This causes problems, just like basically anything else that uses something that is not provided in this function
while True:
message = ws.receive()
ws.send("lol")
我对Flask还不太熟悉,非常需要帮助。
with
解决了。 - High schooler