简体   繁体   中英

Password reset functionality Django-Registration-Redux app

I've installed Django-Registration-Redux app in my project and set up the default one step registration backend and it worked so far. Now i want to extend the functionality of my app by adding password change mechanism. Any idea or link where I can start looking.

Thanks in advance

PD: Django-registration-redux documentation is not related to this topic.

The django-registration-redux supports password change functionality too. For password change the url is http://your-port-number/accounts/password/change . In your localhost once you type in http://your-port-address/accounts/ , you will get all the information regarding the url mappings on the screen itslef. Using those url mappings you can write specific html templates and use them in your app directly. The registration templates can be found here Hope this helps.

The book 'Tango With Django' by Leif Azzopardi and David Maxwell contains a nice example using 'Django-Registration-Redux app' in Chapter 11. This chapter explains in detail - the process to install/setup this module and configure settings, views & urls pattern in clear and concise manner.

According to the book, the module 'Django-Registration-Redux' does not provide templates for the urls it exposes. You need to create these templates manually - because these tend to be application specific . (You should create a directory named registration in your project's template directory to store these template files.) You should also see Anders Hofstee's Templates to take some hints to build your own templates. Mine is as follows (based on his template) :

# <my_django_project_directory>/templates/accounts/password_change_form.html

{% extends "<my_app_name>/base.html" %}
{% block body_block %}
  <h1>Change your password</h1>
  <form method="post" action=".">
    {% csrf_token %}
    {{ form.as_p }}
    <input type="submit" value="Submit" />
  </form>
{% endblock %}

Assuming you have configured the module in the project's settings.py , you should include the following url in the url_patterns list found in your project's urls.py file-

url(r'^accounts/', include('registration.backends.simple.urls')),

As explained by the earlier answers, the url to change the password for a logged in user is http://<projects_root_url>/accounts/password/change . You should provide this url to the logged in user for access by updating the menu item. Continuing with the book's examples I have updated my base template to expose the Password Change url. Consider the following code:

# <my_django_project_directory>/templates/<my_app_name>/base.html
{% if user.is_authenticated %}
    <li><a href="{% url 'auth_logout' %}?next=/rango/">Logout</a></li>
    <li><a href="/accounts/password/change/">Change Password</a></li>
{% else %}
    <li><a href="{% url 'auth_login' %}">Login</a></li>
    <li><a href="{% url 'registration_register' %}">Sign Up</a></li>
{% endif %}

I hope this helps! If not, then I would highly recommend you to go through the book mentioned above! Easy examples, simple to understand instructions, and most importantly, the example works without putting too much effort in any configuration.

Note: Book examples are based on django version 1.9 . My OS is Ubuntu 16.04 and python version - 3.5.2 . My repository containing working example from the book.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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