【发布时间】:2014-01-08 13:42:03
【问题描述】:
如果我有这样的网址:
url(r'^reset/(?P<uid>\w+)/(?P<token>\w+)/$', 'django.contrib.auth.views.password_reset_confirm', name="reset_password")
和这样的 URL 标记:
{% url 'reset_password' uid=uid token=token %}
当我尝试渲染包含标签的页面时为什么会出现此错误:
Reverse for 'reset_password' with arguments '()' and keyword arguments not found
uid 和 token 都是有效的字符串。
【问题讨论】:
-
你的 Django 版本是多少?
-
尝试在 shell 中使用
from django.core.urlresolvers import reverse进行调试,然后使用reverse('reset_password', kwargs={'uid':uid, 'token':token})看看您是否获得了更多信息。此外,如果您的 url conf 是应用程序的一部分,请确保它包含在主 url conf 中。 -
您确定模板上下文中的
uid和token变量中有有效值吗? -
我的猜测是上下文中不存在 token 和/或 uid 变量,尝试显示它们,将其添加到同一模板的其他位置 {{token|pprint}} {{uid|pprint}}
-
可以输出uuid和token的格式吗?他们真的在正则表达式中匹配吗?如果模式与参数不匹配,通常会发生此错误。
标签: python django django-templates django-urls django-1.5