0

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)
1
  • For future reference: the Django 500 error page gives you the option to view the traceback as a copyable traceback; there is a link on the error page, click on that and then copy the whole traceback of the error to your question. I was able to do a quick count of your lines in view.py but the traceback would have helped to pinpoint the exact problem faster. Commented Jan 10, 2014 at 11:13

1 Answer 1

4

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}))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.