Я только начал изучать Django и Python.
Я использую онлайн-книгу djangobook.com
В главе 3 (http://djangobook.com/en/1.0/chapter03/) я пробую пример, чтобы добавить x часов к текущему времени. Мои файлы ниже:
urls.py
from django.conf.urls.defaults import patterns, include, url
from mysite.views import current_datetime
# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()
urlpatterns = patterns('',
(r'^time/$', current_datetime),
(r'^time/plus/(\d{1,2})/$', hours_ahead),
)
views.py
from django.http import HttpResponse
import datetime
def current_datetime(request):
now = datetime.datetime.now()
html = "<html><body>It is now %s.</body></html>" % now
return HttpResponse(html)
def hours_ahead(request, offset):
offset = int(offset)
dt = datetime.datetime.now() + datetime.timedelta(hours=offset)
html = "<html><body>In %s hour(s), it will be %s.</body></html>" % (offset, dt)
return HttpResponse(html)
Но если я попытаюсь перейти к: http://127.0.0.1:8000/time/plus/5/,, я получу NameError at /time/plus/5/
. Я что-то упустил?
Спасибо.
EDIT
Дамп здесь - http://pastebin.com/Hn3aFLzR