,

Forgotten Password In Django

Forgotten Password In Django

Turns out that there are plenty of useful features in the Django admin that I never thought about.

The other day I found the last task of a project of mine was adding the “Forgotten password” feature. It’s basically a standard task included in every users-related project, but the whole process requires few interactions:

  1. clicking ‘forgotten password’ link
  2. writing user email where the password should be send to
  3. verifying email against users database
  4. sending confirmation link
  5. confirming link
  6. choosing password
  7. resetting password

The whole 7-steps list (with UI and backend communications) could be boring and time wasting (usually).

That’s where Django’s templates and integrated behavior comes as a super hero.

Copy all necessary templates from your Django installation

There are few templates that you need to copy from your Django installation. You can find them in your DJANGO_PATH/contrib/admin/templates/registration. You can copy all password-related templates to your templates directory in admin/registration folder.

Some URL paths have to be added to your urls.py file. That’s a sample of mine urls.py with the following URLs:

url(r'^registration/(?P<municipality_id>\d+)

 

The only one taking parameters is the reset confirm one. Most urls are paramless, but you need to pass the user ID and the hashed value for the confirmation link.

After you've added all the templates with the right paths and set all urls, you could just navigate your forgotten password link:
{% trans 'forgot your password' %}

P.S. The whole template pack supports multilingual behavior so after adding the templates, you can run makemessages in order to translate the strings in your language.

Note: in some versions (such as 1.1.1) of Django there is problem with the emailing template. At line 7, remove the named parameters when calling password_reset_confirm view and alter the call only passing values:

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

, proposal, name=’proposal’),
url(r’^login_teacher

The only one taking parameters is the reset confirm one. Most urls are paramless, but you need to pass the user ID and the hashed value for the confirmation link.

After you’ve added all the templates with the right paths and set all urls, you could just navigate your forgotten password link:

 

P.S. The whole template pack supports multilingual behavior so after adding the templates, you can run makemessages in order to translate the strings in your language.

Note: in some versions (such as 1.1.1) of Django there is problem with the emailing template. At line 7, remove the named parameters when calling password_reset_confirm view and alter the call only passing values:

 

, ‘django.contrib.auth.views.login’, {‘template_name’: ‘view_school_upload.html’}),
url(r’^password_reset

The only one taking parameters is the reset confirm one. Most urls are paramless, but you need to pass the user ID and the hashed value for the confirmation link.

After you’ve added all the templates with the right paths and set all urls, you could just navigate your forgotten password link:

 

P.S. The whole template pack supports multilingual behavior so after adding the templates, you can run makemessages in order to translate the strings in your language.

Note: in some versions (such as 1.1.1) of Django there is problem with the emailing template. At line 7, remove the named parameters when calling password_reset_confirm view and alter the call only passing values:

 

, ‘django.contrib.auth.views.password_reset’, {‘template_name’: ‘admin/registration/password_reset_form.html’, ’email_template_name’:’admin/registration/password_reset_email.html’}),
url(r’^password_reset_done

The only one taking parameters is the reset confirm one. Most urls are paramless, but you need to pass the user ID and the hashed value for the confirmation link.

After you’ve added all the templates with the right paths and set all urls, you could just navigate your forgotten password link:

 

P.S. The whole template pack supports multilingual behavior so after adding the templates, you can run makemessages in order to translate the strings in your language.

Note: in some versions (such as 1.1.1) of Django there is problem with the emailing template. At line 7, remove the named parameters when calling password_reset_confirm view and alter the call only passing values:

 

, ‘django.contrib.auth.views.password_reset_done’, {‘template_name’: ‘admin/registration/password_reset_done.html’}),
url(r’^password_reset_confirm/(?P[0-9A-Za-z]+)-(?P.+)

The only one taking parameters is the reset confirm one. Most urls are paramless, but you need to pass the user ID and the hashed value for the confirmation link.

After you’ve added all the templates with the right paths and set all urls, you could just navigate your forgotten password link:

 

P.S. The whole template pack supports multilingual behavior so after adding the templates, you can run makemessages in order to translate the strings in your language.

Note: in some versions (such as 1.1.1) of Django there is problem with the emailing template. At line 7, remove the named parameters when calling password_reset_confirm view and alter the call only passing values:

 

, ‘django.contrib.auth.views.password_reset_confirm’, {‘template_name’: ‘admin/registration/password_reset_confirm.html’}),
url(r’^password_reset_complete

The only one taking parameters is the reset confirm one. Most urls are paramless, but you need to pass the user ID and the hashed value for the confirmation link.

After you’ve added all the templates with the right paths and set all urls, you could just navigate your forgotten password link:

 

P.S. The whole template pack supports multilingual behavior so after adding the templates, you can run makemessages in order to translate the strings in your language.

Note: in some versions (such as 1.1.1) of Django there is problem with the emailing template. At line 7, remove the named parameters when calling password_reset_confirm view and alter the call only passing values:

 

, ‘django.contrib.auth.views.password_reset_complete’, {‘template_name’: ‘admin/registration/password_reset_complete.html’}),
The only one taking parameters is the reset confirm one. Most urls are paramless, but you need to pass the user ID and the hashed value for the confirmation link.

After you’ve added all the templates with the right paths and set all urls, you could just navigate your forgotten password link:

 

P.S. The whole template pack supports multilingual behavior so after adding the templates, you can run makemessages in order to translate the strings in your language.

Note: in some versions (such as 1.1.1) of Django there is problem with the emailing template. At line 7, remove the named parameters when calling password_reset_confirm view and alter the call only passing values:

 

My name is Mario Peshev, a global SME Business Advisor running digital businesses for 20 the past years.

Born in Bulgaria, Europe, I gained diverse management experience through my training work across Europe, North America, and the Arab world. With 10,000+ hours in consulting and training for organizations like SAP, VMware, CERN, I’ve dedicated a huge amount of my time to helping hundreds of SMEs growing in different stages of the business lifecycle.

My martech agency DevriX grew past 50 people and ranks as a top 10 WordPress global agency and Growth Blueprint, my advisory firm, has served 400+ SME founders and executives with monthly ongoing strategy sessions.


Follow me at:

Latest Editions:

Browse by Category

Latest Answers: