错误`找不到'password_reset_confirm'的反向。虽然它在那里

时间:2018-06-06 01:34:30

标签: django

我将urls.py配置为

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.PasswordResetConfirmView.as_view(
    template_name="user/password_reset_confirm.html",
),
name='password_reset_confirm'),

它的名称为password_reset_confirm
但是,浏览器提示它不是有效模式

NoReverseMatch at /user/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:8001/user/password_reset/
Django Version: 1.11.13
Exception Type: NoReverseMatch
Exception Value:    
Reverse for 'password_reset_confirm' not found. 'password_reset_confirm' is not a valid view function or pattern name.

apps setting.py

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    #my apps
    "article",
    "user",
]

项目urls.py

# Project url
urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r"^$", views.index, name="index"),
    url(r'^article/', include('article.urls',namespace='article')),
    url(r'^user/', include('user.urls',namespace='user')),
    # url(r'^register/', include('django.contrib.auth.urls')),
]

如何处理这样的问题?

1 个答案:

答案 0 :(得分:1)

由于您在项目namespace='user'文件中使用urls.py,因此应在代码中使用namespace_value:password_reset_confirm作为urlpattern名称,例如在模板中:

{% url 'user:password_reset_confirm' %}

而不是

{% url 'password_reset_confirm' %}

您可以在doc

中找到更多详细信息