我有一个auth
系统和django-allauth
个库,我有一些登录,注销功能实现,它工作得很好.但我想实现我自己的个人资料页面.对于这一点,我对Django重定向非常困惑.
我有一个名为HomeRequestHandler
的基于类的视图,它继承了一个LoginRequiredMixin
:
from django.contrib.auth.mixins import LoginRequiredMixin
from django.views.generic import TemplateView
class HomeRequestHandler(LoginRequiredMixin, TemplateView):
template_name = "home.html"
在我的URL中,我只将其调用为"":
from django.views.generic import TemplateView
from django.urls import path
from . import views
urlpatterns = [
path("", views.HomeRequestHandler.as_view(), name="home"),
path("profile/", TemplateView.as_view(template_name="account/profile.html"), name="profile"),
]
在我的settings.py
,我有一个LOGIN_REDIRECT_URL
的常量:
LOGIN_REDIRECT_URL = reverse_lazy('profile')
当我try 登录时,我被重定向到"/",即使定义了LOGIN_REDIRECT_URL
.但如果我改变一件事在我看来:
from django.contrib.auth.mixins import LoginRequiredMixin
from django.views.generic import TemplateView
class HomeRequestHandler(LoginRequiredMixin, TemplateView):
template_name = "home.html"
redirect_field_name = "redirect_to"
它将我的urlhttp://localhost:8000/accounts/login/?next=/
更改为http://localhost:8000/accounts/login/?redirect_to=/
,现在常量正常工作,为什么?