Wizard
Wizard

Reputation: 22043

Error `Reverse for 'password_reset_confirm' not found.` though it's there

I configured urls.py as

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

It does have a name password_reset_confirm,
However, the browser prompts it was not a valid pattern

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",
]

The project 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')),
]

How to handle such a problem?

Upvotes: 1

Views: 367

Answers (1)

neverwalkaloner
neverwalkaloner

Reputation: 47354

Since you are using namespace='user' in project urls.py file you should use namespace_value:password_reset_confirm as urlpattern name in your code, for example in template:

{% url 'user:password_reset_confirm' %}

instead of

{% url 'password_reset_confirm' %}

You can find more details in the doc.

Upvotes: 1

Related Questions