我正在关注 Django 教程,但我的一个观点遇到了问题。查看 django 的错误输出时,它告诉我第 62 行有错误:
yr = datetime.datetime(year, 1, 1) months = 12
这是整个视图:
def year(request):
#http://site_name/year/
post_error = ""
year = int(year)
yr = datetime.datetime(year, 1, 1) months = 12
by_month = []
if Post.objects.filter(published__year=year).count():
if year == datetime.datetime.now().year:
months = datetime.datetime.now().month
for month in range(1, months+1):
by_month.append({datetime.datetime(year, month, 1):
Post.objects.filter(published__month=month).filter(published__year=year)})
elif year > datetime.datetime.now().year:
post_error = "It is not yet %d, try an earlier year." % year
else:
post_error = "There are not posts for %d." % year
return render_to_response('year.html', {'by_month':by_month, 'post_error':post_error,},)
如果您需要我未提供的更多信息,请告诉我。谢谢!-克里斯