【发布时间】:2011-08-19 23:26:28
【问题描述】:
我在这里尝试使用 url 模板标签,但它给了我
TemplateSyntaxError at /pastebin/pastes/
Caught NoReverseMatch while rendering: Reverse for 'pastebin_paste_detail' with arguments '('',)' and keyword arguments '{}' not found.
一切对我来说都是正确的,第二次我删除模板标签,模板渲染得非常好。 pastebin_paste_detail 通用视图本身也可以正常工作。这是某种语法问题吗?还是模板标签在 django 1.3 中不起作用?
这是模板:
<title>Paste List</title>
</head>
<body>
{% if object_list %}
<h1>Paste List</h1>
<ul>
{% for obj in object_list %}
<li><a href="{% url pastebin_paste_detail paste.id %}">{{ obj }}</a>
</li>
{% endfor %}
</ul>
{% else %}
<h1>No recent pastes</h1>
{% endif %}
这是 urlconf:
from django.conf.urls.defaults import *
from models import Paste
paste_info = {
'queryset': Paste.objects.all(),
}
urlpatterns = patterns('',
# basically this generic view creates a form based on the specified model
url(r'^$', 'django.views.generic.create_update.create_object', { 'model': Paste }),
url(r'^paste/(?P<object_id>\d+)$', 'django.views.generic.list_detail.object_detail', paste_info, name='pastebin_paste_detail'),
url(r'^pastes/$', 'django.views.generic.list_detail.object_list', paste_info),
)
【问题讨论】:
标签: django