Я стараюсь следовать учебнику django (глава 4, http://www.djangobook.com/en/2.0/chapter04.html). Но ниже код вызывает синтаксическую ошибку.SyntaxError in Django
ошибка:
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)
На будущее: страница ошибок Django 500 дает возможность просмотра отслеживающий как Copyable TRACEBACK; на странице ошибки есть ссылка, щелкните по ней, а затем скопируйте всю трассировку ошибки на свой вопрос. Я смог быстро вычислить ваши строки в 'view.py', но трассировка помогла бы быстрее определить точную проблему. –
Большое вам спасибо: x – user1788781