简体   繁体   English

Django重置密码抛出500错误

[英]Django reset password throws 500 error

I have implemented the Reset password by using django ResetPassword. 我已经使用django ResetPassword实现了Reset密码。 But It throws the 500 error. 但是它会引发500错误。 I don't know how to find the flow & fix it. 我不知道如何找到流程并进行修复。

1.I have created the urls.py 1.我创建了urls.py

    from __future__ import unicode_literals
    from django.conf.urls.static import static
    from django.conf import settings
    from django.contrib import admin
    from django.contrib.auth import views as auth_views
    from django.urls import include, path

    from . import views

    app_patterns = [
        path('login/', auth_views.LoginView.as_view(), name='login'),
        path('logout/', auth_views.LogoutView.as_view(), 
        name='logout'),
        path('signup/', views.Signup.as_view(), name='signup'),
        path(
            'password_reset/',
            auth_views.PasswordResetView.as_view(),
            name='password_reset'
        ),]

Also I have created the HTML files (Refer Screenshot ) 另外,我还创建了HTML文件(请参阅屏幕截图

  • password_reset_form password_reset_form
  • password_reset_done password_reset_done
  • password_reset_confirm password_reset_confirm
  • password_reset_complete password_reset_complete

I don't know what I'm missing here. 我不知道我在这里想念什么。 Can anybody help me out? 有人可以帮我吗? Thanks in advance. 提前致谢。

There are several views required to reset passwords. 重置密码需要几个视图。 The docs suggest that the easiest way to enable them is to include django.contrib.auth.urls . 文档建议启用它们的最简单方法是包括django.contrib.auth.urls

urlpatterns = [
    ...
    path('accounts/', include('django.contrib.auth.urls')),
]

If you want more control, you could include them individually. 如果您希望获得更多控制权,则可以单独包含它们。 Look at the code for django.contrib.auth.urls to see how to include them. 查看django.contrib.auth.urls的代码以了解如何包含它们。 For example the password reset urls would be: 例如,密码重置网址为:

urlpatterns = [
    ...    
    path('password_reset/', views.PasswordResetView.as_view(), name='password_reset'),
    path('password_reset/done/', views.PasswordResetDoneView.as_view(), name='password_reset_done'),
    path('reset/<uidb64>/<token>/', views.PasswordResetConfirmView.as_view(), name='password_reset_confirm'),
    path('reset/done/', views.PasswordResetCompleteView.as_view(), name='password_reset_complete'),
]

Note that in your answer you have 请注意,您的答案中有

app_patterns = [
    ...
]

Django will not use app_patterns automatically. Django不会自动使用app_patterns You should have 你应该有

urlpatterns = [
    ...
]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM