#cannot import name hours_ahead
#Request Method: GET
#Request URL: http://localhost:8000/time/plus/1/
#Exception Type: ImportError?
#Exception Value: cannot import name hours_ahead
#urls.py:
from django.conf.urls.defaults import *
from views import current_datetime, hours_ahead
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 = "It's now %s." % now
return HttpResponse(html)
def hours_ahead(request, offset):
offset = int(offset)
dt = datetime.datetime.now() + datetime.timedelta(hours=offset)
html = "In %s hour(s), it will be %s." % (offset, dt)
return HttpResponse(html)