首页 > django 1.7 NoReverseMatch at /

django 1.7 NoReverseMatch at /

报错提示如下

NoReverseMatch at / Reverse for 'detail' with arguments '()' and
keyword arguments '{'month': 9, 'day': 6, 'title': 'AWK tips', 'year':
2015}' not found. 1 pattern(s) tried:
'(?P<year>[0-9]{4})/(?P<month>0[1-9]|1[0-2])/(?P<day>[0-3)/(?P<title>[\\S ]+)/$'] Request Method: GET Request URL: http://192.168.98.222/ Django
Version: 1.7.1 Exception Type: NoReverseMatch Exception Value:
Reverse for 'detail' with arguments '()' and keyword arguments
'{'month': 9, 'day': 6, 'title': 'AWK tips', 'year': 2015}' not found.
1 pattern(s) tried:
'(?P<year>[0-9]{4})/(?P<month>0[1-9]|1[0-2])/(?P<day>[0-3)/(?P<title>[\\S ]+)/$']

root_url: blog/urls.py

urlpatterns = patterns('',
    url(r'^admin/', include(admin.site.urls)),
    url(r'', include('article.urls', namespace='article')),
)

app_url: article/urls.py

urlpatterns = [
    url(r'^$', views.index, name='index'),
    url(r'^blog/$', views.archive, name='archive'),
    url(r'^(?P<year>[0-9]{4})/$', views.year_archive, name='year_archive'),
    url(r'^(?P<year>[0-9]{4})/(?P<month>0[1-9]|1[0-2])/$', views.month_archive, name='month_archive'),
    url(r'^(?P<year>[0-9]{4})/(?P<month>0[1-9]|1[0-2])/(?P<day>[0-3][0-9])/$', views.day_archive, name='day_archive'),
    url(r'^(?P<year>[0-9]{4})/(?P<month>0[1-9]|1[0-2])/(?P<day>[0-3][0-9])/(?P<title>[\S ]+)/$', views.detail, name='detail'),
] 

index.html

<h2 class="post-title"> <a href="{% url 'article:detail' year=post.pub_date.year month=post.pub_date.month day=post.pub_date.day title=po
st.title %}">{{ post.title }}</h2>

django 新手,这种问题实在不好搜索,很头疼,求解……


月份跟日期的正则表达式没有写正确

(?P<month>[1-9]|1[0-2])/(?P<day>[1-9]|[1-3][0-9])   (不够精准)

你的月份,日期前面没有自动补零

【热门文章】
【热门文章】