0
當我在名爲Practical Django Projects的書上練習時,遇到了一些問題。當我點擊Url關於我的文章的詳細信息時,它返回一個錯誤。
urls.pyDjango ValueError
url(r'^weblog/$','django.views.generic.date_based.archive_index',entry_info_dict),
url(r'^weblog/(P<year>\d{4}/$)','django.views.generic.date_based.archive_year', entry_info_dict),
url(r'^weblog/(P<year>\d{4}/(P<month>\w{3})/$)','django.views.generic.date_based.archive_month', entry_info_dict),
url(r'^weblog/(P<year>\d{4}/(P<month>\w{3})/(P<day>\d{2})/$)','django.views.generic.date_based.archive_day', entry_info_dict),
url(r'^weblog/(?P<year>\d{4}/(?P<month>\w{3})/(P<day>\d{2})/(P<slug>[-\w]+)/$)',"blogCategory.views.entry_detail"),
views.py
def entry_detail(request, year, month, day, slug):
date_stamp=time.strptime(year+month+day, "%Y%b%d")
pub_date=datetime.date(*date_stamp[:3])
entry=get_object_or_404(Entry,pub_date__year=pub_date.year,
pub_date__month=pub_date.month,
pub_date__day=pub_date.day,
slug=slug)
return render_to_response('Entry/entry_detail.html',{'entry': entry })
錯誤:
Traceback :
ValueError at /weblog/2012/dec/04/test22/
time data u'2012/dec/04/test22/dec04' does not match format '%Y%b%d'
Request Method: GET
Request URL: /weblog/2012/dec/04/test22/
Django Version: 1.4.1
Exception Type: ValueError
Exception Value:
time data u'2012/dec/04/test22/dec04' does not match format '%Y%b%d'
Exception Location: /usr/lib/python2.7/_strptime.py in _strptime, line 325
Python Executable: /usr/bin/python
Python Version: 2.7.3
尼斯前捕獲身邊! ^^^ –