Django注册重置密码错误

时间:2017-12-13 14:30:44

标签: python django django-authentication django-registration

我在HMAC workflow的Django应用程序中使用django-registration。注册后,会向用户发送带有激活链接的电子邮件。

我正在使用以下版本:

Django==1.11.1
django-registration==2.3

我看到here有两种不同的视图(功能ou类)可以使用。我在auth_urls.py中添加了一个断点,并在我的应用程序中看到了正在使用的registration.auth_urls_classes

我已创建了一个转到我的重置密码页面的链接:

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

此链接发送到模板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 %}

输入电子邮件地址并发送表格后,电子邮件发送正确(电子邮件已发送给我),但错误发生在:

  

找不到页面(404)请求方法:GET请求   网址:http://127.0.0.1:8000/accounts/password/reset/auth_password_reset_done

我的网址定义如下:

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)

请注意,成功网址的名称(auth_password_reset_done&#39;)是&#34;附加&#34;在链接中,而不是被模式替换。但是,我无法弄清楚原因。

1 个答案:

答案 0 :(得分:1)

您似乎已点击this issue。您可以尝试修复pull request #111,或者自己包含Django的身份验证网址可能更简单:

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

registration.auth_urls will be removed in django-registration 3.0,因此分别包含身份验证网址是未来的最佳方法。