Reputation: 4452
I am following a Django tutorial, and I have run into a problem with one of my views. When looking at the error output from django it tells me that there is a error on line 62:
yr = datetime.datetime(year, 1, 1) months = 12
Here is the entire view:
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,},)
Please tell me if you need anymore information that I have not provided. Thanks! -Chris
Upvotes: 1
Views: 226
Reputation: 1122352
You have two statements on one line; that's a syntax error. Put them on two separate lines:
yr = datetime.datetime(year, 1, 1)
months = 12
Technically, you could also join multiple statements with a ;
semi-colon, but that is generally discouraged.
Upvotes: 2
Reputation: 295
yr = datetime.datetime(year, 1, 1) months = 12
One error: Indention fault in the above line! Move the "months=12" declaration to next line
Upvotes: 1
Reputation: 9813
You missing a newline between function call and var declaration:
year = int(year)
yr = datetime.datetime(year, 1, 1)
months = 12
by_month = []
Upvotes: 3