2
votes

I have the following line in urls.py:

url(r'^changepassword/$', 'django.contrib.auth.views.password_change',
    {'template_name': 'account/changepass.html', 
     'post_change_redirect' : reverse('settings')}, name='change_password'),

However, when loading a different view (with a link to this url) I get a TemplateSyntaxError:

TemplateSyntaxError at /account/

Caught NoReverseMatch while rendering: Reverse for 'change_password' with arguments '()' and keyword arguments '{}' not found.

In template ..../templates/account/settings.html, error at line 7

<p><a href='{% url change_password %}'>Change your password</a>

What could be going wrong?

4

4 Answers

1
votes

You shouldn't use reverse in code that is executed before the url config has been loaded, for example in settings.py, or in your case, the url config.

As of Django 1.4, you can use reverse_lazy instead of reverse in these cases.

0
votes

Removing the reverse call and changing it simply to /settings/ fixed this. I'm not sure why reverse is not working here.

-1
votes

Try: <a href='{% url "change_password" %}'> (with the name in quotes - change_password should be a string, not a template variable)

-1
votes

You can use like this: {% url django.contrib.auth.views.password_change %}