通过渠道设置Django会话变量(http_session)

问题描述 投票:2回答:1

根据Django频道文档,

    You get access to a user’s normal Django session using the http_session 
    decorator - that gives you a message.http_session attribute that behaves 
    just like request.session. You can go one further and use 
    http_session_user which will provide a message.user attribute as well as 
    the session attribute.

无论如何,我可以像这样设置会话变量吗?我确实尝试过,但收到错误消息说NoneType不可迭代。

if 'username' not in message.http_session:
    message.http_session['username'] = 'temp'

换句话说,message.http_session返回NoneType。我尝试使用装饰器@http_session和@channel_session_user_from_http,但它们也没有帮助。

python django session channel django-channels
1个回答
0
投票
foo ='bar'

并且在整个会话期间持续存在

© www.soinside.com 2019 - 2024. All rights reserved.