开发者

Caught NoReverseMatch while rendering with generic PasswordChangeForm Django view

I'm trying to use the generic PasswordChangeForm and pas开发者_如何学Csword_change view in Django, and running into a NoReverseMatch error.

Here is my urls.py:

    (r'^change_pass/','django.contrib.auth.views.password_change', {'post_change_redirect':'/home'}),

Then, I'm trying to call the following from the template:

<form action="{% url django.contrib.auth.views.password_change post_change_redirect="/home/userpage" %}" method="POST">

I get

Caught NoReverseMatch while rendering: Reverse for 'django.contrib.auth.views.password_change' with arguments '()' and keyword arguments '{'post_change_redirect': u'/home/userpage'}' not found.

What am I doing wrong? I thought if an optional variable was declared in the urls.py, you could then override it when calling by specifying it as a named argument. Thanks!


The way you have defined the URL, the post_change_redirect parameter is not optional - in fact it is not accepted at all. The view always get the hard-coded value you have defined in the urlconf. So when the {% url %} tag goes looking for a password_change view that accepts a post_change_redirect parameter, it can't find one, because you haven't defined one.

If you think about the way you have defined the URL, where would the argument go if a caller wanted to override it?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜