我在重置密码时得到这个错误。我有一个登录页面的链接重置忘记的密码,它正确显示模板,但如果我写邮件发送重置链接,它显示这个错误:
localhost/resesetpassword
NoReverseMatch at /resetpassword/
Reverse for 'password_reset_confirm' with arguments '()' and keyword arguments '{'token': '42e-71994a9bf9d36c22eb95', 'uidb64': b'MQ'}' not found. 0 pattern(s) tried: []
Request Method: POST
Request URL: http://localhost/resetpassword/
Django Version: 1.8.2
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'password_reset_confirm' with arguments '()' and keyword arguments '{'token': '42e-71994a9bf9d36c22eb95', 'uidb64': b'MQ'}' not found. 0 pattern(s) tried: []
Exception Location: C:Python34libsite- packagesdjangocoreurlresolvers.py in _reverse_with_prefix, line 496
Python Executable: C:Python34python.exe
Python Version: 3.4.3
Python Path:
['c:\labsoft',
'C:\Python34\lib\site-packages\psycopg2-2.6-py3.4-win-amd64.egg',
'C:\Windows\SYSTEM32\python34.zip',
'C:\Python34\DLLs',
'C:\Python34\lib',
'C:\Python34',
'C:\Python34\lib\site-packages']
Server time: Dom, 7 Jun 2015 21:46:55 -0500
模板渲染错误
In template C:Python34libsite- packagesdjangocontribadmintemplatesregistrationpassword_reset_email.html, error at line 6
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
用红色显示这段代码:
{{ protocol }}://{{ domain }}
{% url 'password_reset_confirm' uidb64=uid token=token %}
我认为错误可能是协议和域参数,但我不知道如何修复它。非常感谢!!
urls . py
from django.conf.urls import patterns, url
from .views import Buscar_view
urlpatterns = patterns('melomanos.views',
url(r'^$','trabajos_all_view',name='url_index'),
url(r'^register/$','register_view',name='vista_registro'),
url(r'^login/$','login_view',name='vista_login'),
url(r'^logout/$','logout_view',name='vista_logout'),
url(r'^perfil/$','registro_view',name='vista_perfil'),
url(r'^publicar/$','trabajomusical_view', name='vista_publicar'),
url(r'^trabajos/$','trabajos_view',name='vista_trabajos'),
url(r'^trabajo/(?P<id_trabajo>.*)/$','solo_trabajo_view', name='vista_trabajo'),
url(r'^buscar/$',Buscar_view.as_view(),name='vista_buscar'),
)
urlpatterns += patterns('',
url(r'^resetpassword/passwordsent/$', 'django.contrib.auth.views.password_reset_done', name='password_reset_done'),
url(r'^resetpassword/$', 'django.contrib.auth.views.password_reset', name="reset_password"),
url(r'^reset/(?P<uidb64>[0-9A-Za-z]+)-(?P<token>,+)/$', 'django.contrib.auth.views.password_reset_confirm'),
url(r'^reset/done/$', 'django.contrib.auth.views.password_reset_complete',{'template_name' : 'registration/password_reset.html', 'post_reset_redirect': '/logout/' }),
)
实际上,您的token参数的正则表达式匹配单个或多个逗号。
您可以使用<token>.+
来匹配任何字符。
你的模式也在寻找uidb64
和token
之间的-
,这条线
{% url 'password_reset_confirm' uidb64=uid token=token %}
传递两个参数,没有-
。
你只需要改变url行,如下所示:
url(r'^reset/(?P<uidb64>[0-9A-Za-z]+)/(?P<token>.+)/$', 'django.contrib.auth.views.password_reset_confirm', name='password_reset_confirm'),
add password_reset_confirm
to url name
urlpatterns += patterns('',
url(r'^resetpassword/passwordsent/$', 'django.contrib.auth.views.password_reset_done', name='password_reset_done'),
url(r'^resetpassword/$', 'django.contrib.auth.views.password_reset', name="reset_password"),
url(r'^reset/(?P<uidb64>[0-9A-Za-z]+)-(?P<token>,+)/$', 'django.contrib.auth.views.password_reset_confirm', name='password_reset_confirm'),
url(r'^reset/done/$', 'django.contrib.auth.views.password_reset_complete',{'template_name' : 'registration/password_reset.html', 'post_reset_redirect': '/logout/' }),
)