Django密码重置 [英] Django Password Reset

查看:57
本文介绍了Django密码重置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Django的新手,我尝试为我的Django应用程序构建身份验证框架,而当我尝试构建password_reset和password_reset_done应用程序时,它会崩溃.我使用的是Django内置框架,尚未进行任何程度的自定义

I am very new to Django and trying to build an authentication framework for my Django app and its falling over when I try and build the password_reset and password_reset_done apps. I am using Django builtin framework and have not customized to any extent

这些是我的网址

from django.conf.urls import url
from django.contrib import admin
from . import views
from django.contrib.auth import views as auth_views



  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"), 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>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
        auth_views.PasswordResetConfirmView.as_view(), name='password_reset_confirm'),
    url(r'^password_reset_complete/$',auth_views.PasswordResetCompleteView.as_view(), name="password_reset_complete"),

这是我收到的错误消息

NoReverseMatch at /partners/password_reset/
Reverse for 'password_reset_confirm' not found. 'password_reset_confirm' is not a valid view function or pattern name.
Request Method: POST
Request URL:    http://127.0.0.1:8000/partners/password_reset/
Django Version: 2.1.1
Exception Type: NoReverseMatch
Exception Value:    
Reverse for 'password_reset_confirm' not found. 'password_reset_confirm' is not a valid view function or pattern name.
Exception Location: C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django-2.1.1-py3.7.egg\django\urls\resolvers.py in _reverse_with_prefix, line 622
Python Executable:  C:\Users\User\AppData\Local\Programs\Python\Python37-32\python.exe
Python Version: 3.7.0
Python Path:    
['C:\\Users\\User\\Desktop\\protectandserve',
 'C:\\Users\\User\\AppData\\Local\\Programs\\Python\\Python37-32\\python37.zip',
 'C:\\Users\\User\\AppData\\Local\\Programs\\Python\\Python37-32\\DLLs',
 'C:\\Users\\User\\AppData\\Local\\Programs\\Python\\Python37-32\\lib',
 'C:\\Users\\User\\AppData\\Local\\Programs\\Python\\Python37-32',
 'C:\\Users\\User\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\site-packages',
 'C:\\Users\\User\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\site-packages\\django-2.1.1-py3.7.egg',
 'C:\\Users\\User\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\site-packages\\pytz-2018.5-py3.7.egg']
Server time:    Thu, 4 Oct 2018 07:49:46 +0000


Error during template rendering
In template C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django-2.1.1-py3.7.egg\django\contrib\admin\templates\registration\password_reset_email.html, error at line 6

Reverse for 'password_reset_confirm' not found. 'password_reset_confirm' is not a valid view function or pattern name.
1   {% load i18n %}{% autoescape off %}
2   {% blocktrans %}You're receiving this email because you requested a password reset for your user account at {{ site_name }}.{% endblocktrans %}
3   
4   {% trans "Please go to the following page and choose a new password:" %}
5   {% block reset_link %}
6   {{ protocol }}://{{ domain }}{% url 'password_reset_confirm' uidb64=uid token=token %}
7   {% endblock %}
8   {% trans "Your username, in case you've forgotten:" %} {{ user.get_username }}
9   
10  {% trans "Thanks for using our site!" %}
11  
12  {% blocktrans %}The {{ site_name }} team{% endblocktrans %}
13  
14  {% endautoescape %}
15  


  [1]: https://i.stack.imgur.com/eGmJT.png

推荐答案

  1. 复制 C:\ Users \ User \ AppData \ Local \ Programs \ Python \ Python37-32 \ lib \ site-packages \ django-2.1.1-py3.7.egg \ django \ contrib \ admin \template \ registration \ password_reset_email.html partners \ templates \ registration \
  2. 将文件 partners \ templates \ registration \ password_reset_email.html 的第6行编辑为

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

  • 更新您的urls.py以指向正确的模板:

  • Update your urls.py to point to right template:

    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'
    ),
    

  • 这篇关于Django密码重置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆