gpt4 book ai didi

python - Django reverse_lazy 配置不当

转载 作者:行者123 更新时间:2023-12-04 08:25:58 33 4
gpt4 key购买 nike

在我的用户注册后,我想将他们重定向到登录页面。但是,reverse_lazy 似乎无法找到我的登录路径。
View .py

from django.shortcuts import render
from django.urls import reverse_lazy
from django.views.generic import CreateView
from . import forms

# Create your views here.
class SignUpView(CreateView):
form_class = forms.UserCreateForm
template_name = 'accounts/signup.html'
#Redirect login page once they have successfully signed up
succes_url = reverse_lazy('login')
网址.py
from django.urls import path
from django.contrib.auth import views as auth_views

from . import views

app_name = 'accounts'

urlpatterns = [
path('login/', auth_views.LoginView.as_view(template_name='accounts/login.html'), name='login'),
path('logout/', auth_views.LogoutView.as_view(template_name='accounts/logout.html'), name='logout'),
path('signup/', views.SignUpView.as_view(template_name='accounts/signup.html'), name='signup'),
]

最佳答案

那是因为您指定了 app_name = … ,在这种情况下,您使用命名空间作为 View 名称的前缀:

class SignUpView(CreateView):
# …
success_url = reverse_lazy('accounts:login')
你还打错字了,是 success_url [Django-doc] ,不是 succes_url .

关于python - Django reverse_lazy 配置不当,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65259071/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com