我正在关注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,},)
如果您还需要我提供的信息,请告诉我。谢谢! -Chris
答案 0 :(得分:1)
你错过了函数调用和var声明之间的换行符:
year = int(year)
yr = datetime.datetime(year, 1, 1)
months = 12
by_month = []
答案 1 :(得分:1)
yr = datetime.datetime(year, 1, 1) months = 12
一个错误:以上行中的压痕故障!移动"月= 12"声明到下一行
答案 2 :(得分:0)
你在一行上有两个陈述;这是一个语法错误。把它们分成两行:
yr = datetime.datetime(year, 1, 1)
months = 12
从技术上讲,您也可以使用;
分号加入多个语句,但通常不鼓励这样做。