project_kingz
project_kingz

Reputation: 249

using django authentication password_reset_confirm error

I have an error with password reset. If I attempt to reset using an invalid email I get the password reset sent notice. If I use a valid email I get NoReverseMatch error message

from django.conf.urls import url
from django.contrib import admin
from . import views
from django.contrib.auth import views as auth_views
from django.urls import reverse, reverse_lazy, resolve

    # Password URL's ###################################################################################################

    url(r'^change-password/$', views.change_password, name='change_password'),


    url(
        r'^password_reset/$',
        auth_views.PasswordResetView.as_view(
            template_name="registration/password_reset.html",
            email_template_name="registration/password_reset_email.html",
            success_url=reverse_lazy("partners:password_reset_done"),  # might be required
        ),
        name='password_reset'
    ),

    url(r'^password_reset_done/',
        auth_views.PasswordResetDoneView.as_view(

        ),
        name='password_reset_done'
    ),


    url(r'^password_reset_confirm/(?P<uidb64>[0-9A-Za-z]+)-(?P<token>.+)/$',
        auth_views.PasswordResetConfirmView.as_view(
            template_name="registration/password_reset_confirm.html",
            success_url=reverse_lazy("partners:password_reset_complete"),  # might be required
        ),
        name='password_reset_confirm'
    ),


    url(r'^password_reset_complete/$',auth_views.PasswordResetCompleteView.as_view(), name="password_reset_complete"),
]

Please see my screen grabs for my project structure and the error message

project structure

error message received

{% block head %}
<meta charset="UTF-8">
<title>Welcome ! You can login here !</title>
{% endblock head %}

{% block body %}
    {% block content %}
        <div class="container">
            <div class="row">
                <div class="col-sm-6 col-md-3">
                    <h3>Password Reset Email</h3>
                    <p>Provide your registered email address </p>
                        {% autoescape off %}
                                To initiate the password reset process for your {{ user.get_username }} TestSite Account,
                                click the link below:


                                {{ protocol }}://{{ domain }}{% url 'partners:password_reset_confirm' uidb64=uid token=token %}


                                If clicking the link above doesn't work, please copy and paste the URL in a new browser
                                window instead.


                                Sincerely,
                                The AV's BlogTeam
                        {% endautoescape %}
                </div>
            </div>
        </div>
    {% endblock content %}
{% endblock body %}

I am building this in a "partners app" where I have templates/registration with the above password_reset_confirm.html

Password reset email is as below

{% load i18n %}{% autoescape off %}
{% blocktrans %}You're receiving this email because you requested a password reset for your user account at {{ site_name }}.{% endblocktrans %}

{% trans "Please go to the following page and choose a new password:" %}
{% block reset_link %}
{{ protocol }}://{{ domain }}{% url 'partners:password_reset_confirm' uidb64=uid token=token %}
{% endblock %}
{% trans "Your username, in case you've forgotten:" %} {{ user.get_username }}

{% trans "Thanks for using our site!" %}

{% blocktrans %}The {{ site_name }} team{% endblocktrans %}

{% endautoescape %}

PLEASE HELP

Upvotes: 0

Views: 209

Answers (1)

Alasdair
Alasdair

Reputation: 309109

If you want Django to use the template from your partners app, you need to move partners above django.contrib.admin in your INSTALLED_APPS setting.

I would suggest that you move the password reset urls into a urls.py that does not use the partners namespace. Using {% url 'partners:password_reset_confirm' ... %} will fix this specific error, but there are several other places that you will have to make changes to use the namespace, and I don't think it's worth the effort.

Upvotes: 1

Related Questions