【问题标题】:Set Django session variables through channels (http_session)通过通道设置 Django 会话变量 (http_session)
【发布时间】:2018-06-16 04:22:15
【问题描述】:

根据 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 is not iterable。

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】:

你只是设置了变量。

foo = '酒吧'

并且它在整个会话中持续存在

【讨论】:

    猜你喜欢
    • 2011-12-07
    • 1970-01-01
    • 2014-12-11
    • 2016-03-20
    • 2014-02-03
    • 2012-12-14
    • 2016-11-07
    • 2018-05-03
    • 2020-01-05
    相关资源
    最近更新 更多