[Fixed]-Django reset_password_confirm TemplateSyntaxError problem

24👍

Most likely it is an issue with your urls.py. You need to setup the right pattern to grab the uidb36 and token values passed as URL parameters. If not, it will throw a similar error to what you see above.

Something like:

(r'^reset/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$', 'django.contrib.auth.views.password_reset_confirm', {'template_name' : 'registration/password_reset.html',  'post_reset_redirect': '/logout/' })

registration/password_reset.html – is my custom template

logout – is my custom logout action

6👍

I had this issue in Django 1.3, and wasted a lot of time because the error can mask a number of underlying issues.

I needed to add this to the top of the reset email template:

{% load url from future %}

Also, the example in the Django docs didn’t match the sample url:

{{ protocol}}://{{ domain }}{% url 'auth_password_reset_confirm' uidb36=uid token=token %}

So I had to change the auth_password_reset_confirm above to password_reset_confirm.

👤greg

6👍

If you’re using Django 1.6+ and run into something like this it could be that you need to update uidb36 to uidb64 in both your template and your urls.

Example url:

url(r'^password/reset/confirm/(?P<uidb64>[0-9A-Za-z]+)-(?P<token>.+)/$',
auth_views.password_reset_confirm

and reset link in template:


{{ protocol}}://{{ domain }}{% url 'django.contrib.auth.views.password_reset_confirm' uidb64=uid token=token %}

2👍

For Django 1.8+ users, just copy this URL to your main urls.py file, so that it recognizes the URL name

  url(r'^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
        'django.contrib.auth.views.password_reset_confirm',
        name='password_reset_confirm'),

And add this mentioned by: @Lunulata to your password_reset_email.html file:

{{ protocol}}://{{ domain }}{% url 'django.contrib.auth.views.password_reset_confirm' uidb64=uid token=token %}

👤K2A

1👍

Try adding following to your urls.py

(r'^reset/(?P<uidb36>[0-9A-Za-z]{1,13})-(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', 'django.contrib.auth.views.password_reset_confirm'),
👤Amrut

0👍

I found this to work, copied from the default url

url(r'^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
auth_views.password_reset_confirm, name='password_reset_confirm'),

0👍

Just add this line to your urls.py:

url('^', include('django.contrib.auth.urls')),

This enables the django reset_password workflow.

Then override your login.html to include the line:
<div class="password-reset-link">
href="{{ password_reset_url }}">{% trans 'Forgotten your password or username?' %}</a></div>

Now you should be able to use the builtin Django PasswordResetView included with Django as long as your email settings are set up.

0👍

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/<uidb64>/<token>/',
          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

Leave a comment