我與is_authenticated
掙扎返回True
:is_authenticated返回ture AnonymousUser
u = request.user
if u.is_authenticated:
raise Exception('I am said to be authenticated, but I really am not.')
爲了澄清,Django的調試視圖正確識別u
爲AnonymousUser
:
u <django.contrib.auth.models.AnonymousUser object at 0x9e76f4cc>
更奇怪的是,模板內is_anonymous
工作正常:
{% if not request.user.is_authenticated %}
We are anonymous.
{% endif %}
這是爲什麼?
可能重複的[Django:is \ _authenticated是\ _anonymous在註銷後都返回true](http://stackoverflow.com/questions/4298387/django-is-authenticated-and-is-anonymous-both-return註銷後) –