Reputation: 1155
I am trying to follow the django tutorial, (chapter 4, http://www.djangobook.com/en/2.0/chapter04.html). But the code further below throws a syntax error.
error:
Request Method: GET
Request URL: http://127.0.0.1:1222/hello/
Exception Type: SyntaxError
Exception Value: invalid syntax (views.py, line 23)
Exception Location: /home/milad/djangobook/djangobook/urls.py in <module>, line 2
urls.py
from django.conf.urls import patterns, include, url
from djangobook.views import hello, showtime, plustime
urlpatterns = patterns('',('^hello/$',hello),('^time/$',showtime),(r'^time/plus/(\d{1,2})/$',plustime),
)
views.py
from django.http import HttpResponse
from django.template.loader import get_template
from django.template import Context
import datetime
def hello(request):
return HttpResponse ("Hello Dear Django!")
def showtime(request):
now = datetime.datetime.now()
t = get_template('showtime.html')
html = t.render(Context({'time':now}))
return HttpResponse(html)
def plustime(request,plus):
try:
plus = int(plus)
except ValueError:
raise Http404()
now = datetime.datetime.now() + datetime.timedelta(hours=plus)
t = get_template('plustime.html')
html = t.render(Context({'plus1':now})
return HttpResponse(html)
Upvotes: 0
Views: 413
Reputation: 1121744
You are missing a closing parenthesis on the preceding line:
html = t.render(Context({'plus1':now})
# --- 1 --2 -- 2 but no 1
add )
at the end there:
html = t.render(Context({'plus1':now}))
Upvotes: 4