1、在View视图函数中的检测方法:

if request.user.is_authenticated():
# 用户已登陆
else:
# 用户未登陆

2、在HTML模板文件中的检测方法:

先要确保request对象在模板的context中,即在settings.py文件配置:
Django中判断用户是否登陆
然后即可使用用RequestContext来判断,代码如下:
{% if request.user.is_authenticated %}
用户已登陆。
{% else %}
用户未登陆。
{% endif %}

相关文章:

  • 2021-12-26
  • 2021-11-11
  • 2021-12-09
  • 2021-08-06
  • 2021-11-22
  • 2021-09-18
  • 2021-09-22
  • 2021-08-14
猜你喜欢
  • 2021-12-09
  • 2021-07-30
  • 2019-08-23
  • 2021-11-06
  • 2021-11-05
  • 2021-09-29
  • 2018-09-12
  • 2018-11-07
相关资源
相似解决方案