Django reset_password_confirm TemplateSyntaxError problem

后端 未结 8 1369
夕颜
夕颜 2020-12-13 20:39

when I use django.contrib.auth.views.password_reset_confirm without arguments at all it works and I can render the template without any problem, when adding

8条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-13 21:05

    if you are using app_name in every urls.py

    suppose you have an app and in that app in urls.py you have mentioned app_name="accounts" in order to retrieve the page you need to mention two things template_name and success_url inside the PasswordResetView(template_name="accounts/password_reset.html" , success_url= reverse_lazy('accounts:password_reset_sent'))

    dont forget to import reverse_lazy from django.urls inside urls.py

    so your final code of accounts/urls.py should look like

    My app name is landing instead of accounts

    from django.urls import path
    from . import views
    from django.contrib.auth import views as auth_views
    from django.urls import reverse_lazy
    
    app_name='landing'
    
    urlpatterns = [
         path('',views.home,name="home"),
         path('terms/',views.terms,name="terms"),
         path('login/',views.loginUser,name="login"),
         path('signup/',views.signupUser,name="signup"),
         path('about/',views.about,name="about"),
         path('logout/',views.logoutUser,name="logout"),
    
         path('password_reset/',
              auth_views.PasswordResetView.as_view(template_name='landing/password_reset.html',success_url=reverse_lazy('landing:password_reset_done')),
                   name="password_reset"),
    
         path('password_reset_sent/',
              auth_views.PasswordResetDoneView.as_view(template_name='landing/password_reset_sent.html'),
              name="password_reset_done"),
    
         path('reset///',
              auth_views.PasswordResetConfirmView.as_view(template_name='landing/password_reset_form.html',success_url=reverse_lazy('landing:password_reset_complete')),
              name="password_reset_confirm"),
    
         path('password_reset_complete/',
              auth_views.PasswordResetCompleteView.as_view(template_name='landing/password_reset_done.html'),
              name="password_reset_complete"),
    
    ]
    

    you have to use app_name: before the name of url you have mentioned it is very important

提交回复
热议问题