Django反向()问题
我在这里缺少一些非常基本的东西。
我正在尝试重用 django 的更改密码视图。我在 urls.py:
(r'^change-password/$', 'profile.views.change_password', {},'change_password'),
url(r'^change-password-done/$', 'profile.views.password_change_done', name='django.contrib.auth.views.password_change_done'),
和相应的views.py: 中
from django.contrib.auth.views import password_change, password_change_done
def change_password(request,template_name="password_change_form.html"):
"""Change Password"""
return password_change(request,template_name=template_name)
def password_change_done(request, template_name="password_change_done.html"):
return render_to_response(template_name,(),context_instance= RequestContext(request))
有以下内容,但出现以下错误:
反转为 'django.contrib.auth.views.password_change_done' 带参数“()”和关键字 未找到参数“{}”。
查看源代码并看到这一行:
post_change_redirect = reverse('django.contrib.auth.views.password_change_done')
如果我将 urls.py 条目更改为以下,我不会收到上述错误:
url(r'^change-password-done/$', 'django.contrib.auth.views.password_change_done', name='anything'),
但我很困惑,因为verse()应该使用“name”参数进行查找?我在这里缺少什么?
我正在使用 django 1.2.3
I am missing something really basic here.
I am trying to reuse django's change password views. I have following in urls.py:
(r'^change-password/
and in corresponding views.py:
from django.contrib.auth.views import password_change, password_change_done
def change_password(request,template_name="password_change_form.html"):
"""Change Password"""
return password_change(request,template_name=template_name)
def password_change_done(request, template_name="password_change_done.html"):
return render_to_response(template_name,(),context_instance= RequestContext(request))
but I am getting following error:
Reverse for
'django.contrib.auth.views.password_change_done'
with arguments '()' and keyword
arguments '{}' not found.
looked at the source and saw this line:
post_change_redirect = reverse('django.contrib.auth.views.password_change_done')
If I change my urls.py entry to following , I do not get the above error:
url(r'^change-password-done/
but I am confused as reverse() should look-up using the "name" parameter? What am I missing here?
I am using django 1.2.3
, 'profile.views.change_password', {},'change_password'),
url(r'^change-password-done/
and in corresponding views.py:
but I am getting following error:
Reverse for
'django.contrib.auth.views.password_change_done'
with arguments '()' and keyword
arguments '{}' not found.
looked at the source and saw this line:
If I change my urls.py entry to following , I do not get the above error:
but I am confused as reverse() should look-up using the "name" parameter? What am I missing here?
I am using django 1.2.3
, 'profile.views.password_change_done', name='django.contrib.auth.views.password_change_done'),
and in corresponding views.py:
but I am getting following error:
Reverse for
'django.contrib.auth.views.password_change_done'
with arguments '()' and keyword
arguments '{}' not found.
looked at the source and saw this line:
If I change my urls.py entry to following , I do not get the above error:
but I am confused as reverse() should look-up using the "name" parameter? What am I missing here?
I am using django 1.2.3
, 'django.contrib.auth.views.password_change_done', name='anything'),
but I am confused as reverse() should look-up using the "name" parameter? What am I missing here?
I am using django 1.2.3
, 'profile.views.change_password', {},'change_password'), url(r'^change-password-done/and in corresponding views.py:
but I am getting following error:
Reverse for
'django.contrib.auth.views.password_change_done'
with arguments '()' and keyword
arguments '{}' not found.
looked at the source and saw this line:
If I change my urls.py entry to following , I do not get the above error:
but I am confused as reverse() should look-up using the "name" parameter? What am I missing here?
I am using django 1.2.3
, 'profile.views.password_change_done', name='django.contrib.auth.views.password_change_done'),and in corresponding views.py:
but I am getting following error:
Reverse for
'django.contrib.auth.views.password_change_done'
with arguments '()' and keyword
arguments '{}' not found.
looked at the source and saw this line:
If I change my urls.py entry to following , I do not get the above error:
but I am confused as reverse() should look-up using the "name" parameter? What am I missing here?
I am using django 1.2.3
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
乔希有解释,但你做错了。如果您想覆盖
post_save_redirect
,请在调用视图时将其作为参数传递:请参阅 文档。
Josh has the explanation, but you are doing this wrong. If you want to overrride the
post_save_redirect
, then pass that in as a parameter when you call the view:See the documentation.
reverse
函数不仅仅对名称进行查找。反向文档。
因此,通过执行
reverse('django.contrib.auth.views.password_change_done')
,它将在urls.py
正则表达式中查找该视图名称,并回退到如果视图名称无法解析,则查找name
关键字参数。The
reverse
function doesn't just do lookups on name.Reverse Documentation.
So, by doing
reverse('django.contrib.auth.views.password_change_done')
, it will look up that view name within theurls.py
regexes, and fallback to looking for thename
keyword argument if the viewname doesn't resolve.