如何在password_reset_complete Django中重定向登录链接

时间:2019-05-23 13:33:19

标签: python django

password_reset_complete中的登录链接将用户定向到帐户/登录,而不是帐户/登录。我该如何解决?

错误:

Using the URLconf defined in tutorial.urls, Django tried these URL patterns, in this order:
[name='login_redirect']
admin/
account/
The current path, accounts/login/, didn't match any of these.

accounts / urls.py:

urlpatterns = [

path('', views.home, name="home"),
path('login/', LoginView.as_view(template_name='accounts/login.html'), name='login'),
path('logout/', LogoutView.as_view(template_name='accounts/logout.html'), name='logout'),
path('register/', views.register, name='register'),
path('profile/', views.view_profile, name='profile'),
path('profile/edit/', views.edit_profile, name='profile-edit'),
path('change-password/', views.change_password, name='change-password'),
path('reset-password/', PasswordResetView.as_view(), name='reset-password'),
path('reset-password/done/', PasswordResetDoneView.as_view(), name='password_reset_done'),
path('reset-password/confirm/<uidb64>/<token>/',
         PasswordResetConfirmView.as_view(), name='password_reset_confirm'),
path('reset-password/complete/', PasswordResetCompleteView.as_view(), name='password_reset_complete'),

main / urls.py:

urlpatterns = [
path(r'', views.login_redirect, name='login_redirect'),
path('admin/', admin.site.urls),
path('account/', include('accounts.urls')),

]

settings.py:

LOGIN_REDIRECT_URL = '/account/'

谢谢

1 个答案:

答案 0 :(得分:2)

似乎您定义了错误的网址格式

urlpatterns = [
    path(r'', views.login_redirect, name='login_redirect'),
    path('admin/', admin.site.urls),
    path('accounts/', include('accounts.urls')), # use "accounts" instead of "account"
]

注意

现在,您所有的 /account/.. 网址都将更改为 /accounts/...