Django-注册重设密码错误

Django-registration reset password error

我在 HMAC workflow 的 Django 应用程序中使用 django-registration。注册后会向用户发送一封包含激活 link 的电子邮件。

我使用的是以下版本:

Django==1.11.1
django-registration==2.3

我看到 here that there are two different views (function ou class) that could have being used. I put a breakpoint in the auth_urls.py and saw that in my application the registration.auth_urls_classes 正在使用。

我创建了一个 link 以转到我的重设密码页面:

<a class="g-font-size-12" href="{% url 'auth_password_reset' %}">Esqueceu a senha?</a>

这个link发送到模板password_reset_form.html,如下图:

{% extends "base.html" %}
{% load i18n %}

{% block content %}
<div class="row justify-content-center g-py-180">
    <div class="col-sm-10 col-md-9 col-lg-4">
        <header class="text-center g-mb-30">
            <h2 class="h2 g-color-black g-font-weight-600"> Resete sua senha </h2>
        </header>
        <form method="post" action="{% url 'auth_password_reset' %}">
            <h1 class="h5 g-font-weight-300">Forneça seu endereço de email e nós enviaremos para você um link para alterar sua senha.</h1>


            {% csrf_token %}

            {% for field in form %}
                {% if field.name ==  'email' %}
                    <div class="mb-4 mt-4">
                      <input class="form-control g-color-black g-bg-white g-bg-white--focus g-brd-gray-light-v4
                         g-brd-primary--hover rounded g-py-15 g-px-15" type="email" required
                         placeholder="harry_potter@gmail.com" name="{{ field.html_name }}" id="{{ field.auto_id }}">
                    </div>
                {% endif %}
            {% endfor %}
            <button class="g-min-width-100x btn btn-md u-btn-primary rounded g-py-13 g-px-25" type="submit" value="Submit">Enviar email de redefinição de senha</button>
        </form>
    </div>
</div>
{% endblock %}

输入电子邮件地址并发送表格后,电子邮件已正确发送(电子邮件到达我这里),但出现以下错误:

Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/accounts/password/reset/auth_password_reset_done

我的 url 定义如下:

urlpatterns = [
    url(r'^$', TemplateView.as_view(template_name='index.html'), name='home'),

    #authentication
    url(r'^accounts/', include('registration.backends.hmac.urls')),

    url(r'^profile/', include('pxgbr2.account_settings.urls', namespace='profile')),
    url(r'^admin/', admin.site.urls),
]

if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, 
document_root=settings.MEDIA_ROOT)

请注意,成功的名称 url (auth_password_reset_done') 在 link 中是 "appended",而不是被模式替换。不过我不知道为什么。

您似乎已经点击了 this issue. There is a fix pull request #111 您可以尝试,或者自己包含 Django 的身份验证 URL 可能更简单:

url('^accounts/', include('django.contrib.auth.urls')),
url('^accounts/', include('registration.backends.hmac.urls')),

registration.auth_urlswill be removed in django-registration 3.0,所以单独包含 auth url 是未来最好的方法。