【发布时间】:2012-07-18 19:44:10
【问题描述】:
当我转到 /blog/tag/1 查看第一个现有标记项时,它呈现对 tag.html 的响应,我得到一个异常:“Caught NoReverseMatch while rendering: Reverse for ''add-node'' with未找到参数“()”和关键字参数“{}”。”
我的 URLs.py 中有类似的内容:
url(r'^blog/add_node/$', 'Alpha.Gamma.views.add_node', name='add-node'),
Views.py:
def add_node(request):
tag = Tag.objects.all()
action = reverse("add-node-proc")
title = "Submit Article"
return render_to_response("blog/add_node.html", add_csrf(request, action=action, title=title, tags=tag, button="Submit Article"))
tag.html的模板有:
<a id="new_node" class="buttont" href="{% url 'add-node' %}">Add new blog post</a>
<br />
<br />
我得到的错误:
渲染时 NoReverseMatch:未找到带有参数“()”和关键字参数“{}”的“添加节点”的反向。
它突出显示了我在上面为 tag.html 放置的行。
add_node.html 是一个简单的表单模板。我做错了什么,文档说我做的一切都是正确的。
如果我将模板上的“url 'add-node'”更改为“url Alpha.Gamma.views.add_node”,一切都会突然运行---为什么???我不明白这个 django url 调度程序。
是的,我已经多次重启了 apache。
【问题讨论】:
-
尝试在模板中的 add-node 周围加上引号,看看是否有效。
-
它通过了。但是文档误导了我并告诉我使用 {% url 'arch-summary' 1945 %} {% url 'full-archive' 2007 %} docs.djangoproject.com/en/dev/topics/http/urls
-
我鼓励你发送错误报告:)
标签: django django-templates django-urls