我有一个小观点:
def AccountHome(request):
return render(request, 'myapp/account/accounthome.html', {
})
在之前的 View 中,我使用过:
if user is not None and user.is_active
在使用 native 表单类时检查用户是否已经通过身份验证,例如:AuthenticationForm
,例如在登录用户时。
但是在这个 View 上我没有使用它,有没有办法在不再次使用这个 AuthenticationForm
类的情况下验证用户是否登录?此
View 的目的是在登录时显示主屏幕,因此再次扩展该
AuthenticationForm`类似乎不直观。
有什么帮助或想法吗?
谢谢
最佳答案
使用is_authenticated()
方法
像这样:if request.user.is_authenticated():
您可以在此处找到引用:https://docs.djangoproject.com/en/dev/ref/contrib/auth/#methods
关于python - 使用帐户身份验证来验证是否已登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19503195/