动态url加载
url:
from django.conf.urls import url from myApp import views urlpatterns = [ # url(r'^time/plus/(\d+)/$', views.hours_ahead), url(r'^time/plus/(\d{1,2})/$', views.hours_ahead),
views:
# coding=utf-8 import datetime from django.http import HttpResponse, Http404 def hours_ahead(request, offset): try: offset = int(offset) except ValueError: raise Exception("............") dt = datetime.datetime.now() + datetime.timedelta(hours=offset) html = "In %s hour(s), it will be %s." % (offset, dt) return HttpResponse(html)