我正在尝试与活跃用户和频道会话合作。 但是,当我登录时,我的频道通常会给出AnonymousUser。普通视图中需要@login)
同样在每次通话时,我的会话似乎都会保存。
@channel_session_user_from_http
def ws_connect(message):
print(message['headers'])
drop_map(message)
# message.user.active_map works like it is supposed to
message.user.active_map.websocket_group.add(message.reply_channel)
def ws_message(message):
payload = json.loads(message['text'])
payload['reply_channel'] = message.content['reply_channel']
Channel("maps.receive").send(payload)
@channel_session_user
@catch_client_error
def map_background(message):
# Now message.user is anonymous user and code crashes
map_obj = message.user.active_map
character = message.user.active_character
grid = map_obj.template.static_grid.slice_grid(character.location.x, character.location.y, message.user.settings)
message.reply_channel.send({
"text": json.dumps({
"action": "load_background",
"name": map_obj.name,
"grid": grid,
}),
})
在ws_connect上它一切正常,我得到了我的登录用户。 但是,当我在map_background上进行调用时,突然我的用户是匿名用户。我使用redis作为我的频道后端。
标题:[[b'缓存控制',b' no-cache'],[b'接受编码',b' gzip,deflate&# 39;],[b' cookie',b' csrftoken = mlI5ODljY3eJ3Le1dPnv1VrmZznAVCbo7XU9JAIK8bb8urjbcEimsZRUqczCzzdI; sessionid = druv90lxnz36yahnr7zcybojh5xlzdl2'],[b' connection',b' keep-alive,Upgrade'],[b' sec-websocket-version',b' 13'],[b'来源',b' http://localhost:8000'],[b'#websocket-extensions',b'渗透-deflate'],[b' host',b' localhost:8000'],[b' pragma',b' no-cache'] ,[b'升级',b' websocket'],[b'接受语言',b' en-US,en; q = 0.5' ],[b'用户代理',b' Mozilla / 5.0(X11; Linux x86_64; rv:50.0)Gecko / 20100101 Firefox / 50.0'],[b' sec- websocket-key',b' mx5wy9w8HxH2dQ6ls5 / rUg =='],[b'接受',b' text / html,application / xhtml + xml,application / xml; q = 0.9, / 的; q = 0.8']]