我得到完整的錯誤消息「反向找不到」是:Django的密碼重置投擲「password_reset_done」
Reverse for 'password_reset_done' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
我試圖使用標準DJANGO AUTH庫來實現登入,註銷,密碼重置和註冊功能/視圖到我的網站。
我使用的是蟒蛇4.6包,我導入Django的庫如下
from django.contrib.auth import views as auth_views
的(相關)urlpatterns的我已經是:
url(r'^password_reset/$', auth_views.password_reset, name='password_reset'),
url(r'^password_reset/done/$', auth_views.password_reset_done, name='password_reset_done'),
url(r'^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', auth_views.password_reset_confirm, name='password_reset_confirm'),
url(r'^reset/done/$', auth_views.password_reset_complete, name='password_reset_complete'),
如果我去了URL
/password_reset/done/
我到達了頁面。
如果我去的URL
/password_reset/
我得到的失敗,相反的錯誤。
我一直在讀2天的文檔,但我似乎並沒有能夠找出原因
url(r'^password_reset/done/$', auth_views.password_reset_done, name='password_reset_done'),
阻止Django的逆轉。有沒有人有任何想法?
非常感謝!
回溯這裏太瞭解更多詳情:
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/password_reset/
Django Version: 1.10.5
Python Version: 3.5.2
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'bootstrap3',
'app1']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback:
File "E:\Programming\Anaconda3_4.2.0\lib\site-packages\django\core\handlers\exception.py" in inner
39. response = get_response(request)
File "E:\Programming\Anaconda3_4.2.0\lib\site-packages\django\core\handlers\base.py" in _get_response
187. response = self.process_exception_by_middleware(e, request)
File "E:\Programming\Anaconda3_4.2.0\lib\site-packages\django\core\handlers\base.py" in _get_response
185. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "E:\Programming\Anaconda3_4.2.0\lib\site-packages\django\contrib\auth\views.py" in inner
47. return func(*args, **kwargs)
File "E:\Programming\Anaconda3_4.2.0\lib\site-packages\django\utils\decorators.py" in _wrapped_view
149. response = view_func(request, *args, **kwargs)
File "E:\Programming\Anaconda3_4.2.0\lib\site-packages\django\contrib\auth\views.py" in password_reset
189. post_reset_redirect = reverse('password_reset_done')
File "E:\Programming\Anaconda3_4.2.0\lib\site-packages\django\urls\base.py" in reverse
91. return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))
File "E:\Programming\Anaconda3_4.2.0\lib\site-packages\django\urls\resolvers.py" in _reverse_with_prefix
392. (lookup_view_s, args, kwargs, len(patterns), patterns)
Exception Type: NoReverseMatch at /password_reset/
Exception Value: Reverse for 'password_reset_done' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
添加一些額外的信息:
項目網址:
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^app1/',include('app1.urls')),
url(r'^',include('app1.urls')),
]
爲 'APP1 \註冊\ login.html的' 模板代碼正確呈現:
{% block title %}Login{% endblock %}
{% block content %}
<h2>Login</h2>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Login</button>
</form>
{% endblock %}
爲「APP1 \註冊\ password_reset_done.html」模板代碼引發錯誤:
{% block content %}
<p>
We've emailed you instructions for setting your password, if an account exists with the email you entered.
You should receive them shortly.
</p>
<p>
If you don't receive an email, please make sure you've entered the address you registered with,
and check your spam folder.
</p>
{% endblock %}
我想用python3.6和Django 1.11和一個空的項目,你的urls.py的正則表達式沒問題,我懷疑django渲染的模板是問題。你有沒有試圖刪除/管理目錄在你的模板目錄? –
請分享所有這些網址正在使用的模板代碼。 –
對不起,延遲很長(時差),但我在上面添加了一些額外的信息。我正在審查模板代碼,但還沒有太多。 – user3535074