我有两个一般性问题:
根据标题,有没有办法让有活跃会话的用户尝试访问/login.html转而使用/home.html?
我正在使用Django的默认PasswordChangeForm,当用户更改密码时,它会让他们使用旧密码。所以这有效:
旧密码:123456
新密码:123456
重复新密码:123456
谢谢!
答案 0 :(得分:3)
对于您的第一个问题,假设您通过视图提供/login.html
,您可以轻松检查用户是否已登录,并且在这种情况下提供302这样的重定向。
from django.shortcuts import redirect
def my_view(request):
if request.user.is_authenticated:
return redirect('/home.html')
完整文档https://docs.djangoproject.com/en/1.11/topics/auth/default/#the-raw-way