我有以下内容urlpatterns
:
urlpatterns = patterns('',
url(r'^new$', 'webapp.views.new_post', name="new_post"),
url(r'^$', 'webapp.views.all_posts', name="main"),
url(r'^post/(\d{4})/(\d{2})/(\d{2})/$', 'webapp.views.single_post', name="single_post"),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
# url(r'^admin/', include(admin.site.urls)),
)
还有一个看起来像这样的模板:
{% for i in posts %}
<h3><a href={% url 'single_post' i.created_at.year i.created_at.month i.created_at.day %}>{{i.title}}</a></h3>
Posted at: {{i.created_at}}
<br>
<br>
{{i.text}}
<hr>
{% endfor %}
但我一直收到一个NoReverseMatch
例外说Reverse for 'single_post' with arguments '(2012, 9, 30)' and keyword arguments '{}' not found.
编辑:我在 Python 2.7 上使用 Django 1.4.1