使用Django身份验证password_reset_confirm错误

时间:2018-10-05 09:47:39

标签: django

我在重置密码时出错。如果我尝试使用无效的电子邮件进行重置,则会收到密码重置通知。如果我使用有效的电子邮件,则会收到NoReverseMatch错误消息

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"),
]

请查看我的屏幕截图,了解我的项目结构和错误消息

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 %}

我正在“合作伙伴应用”中构建此应用,其中我具有上面的password_reset_confirm.html模板/注册信息

密码重置电子邮件如下

{% 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 %}

请帮助

1 个答案:

答案 0 :(得分:1)

如果您希望Django使用partners应用中的模板,则需要在partners设置中将django.contrib.admin移动到INSTALLED_APPS上方。

我建议您将密码重置URL移到不使用urls.py名称空间的partners中。使用{% url 'partners:password_reset_confirm' ... %}可以解决此特定错误,但是您还必须在其他几个地方进行更改才能使用名称空间,我认为这样做不值得。