标签:
from django.http import HttpResponse def hello(request): return HttpResponse("Hello world")
from django.conf.urls.defaults import * from views import hello urlpatterns = patterns(‘‘, (‘^hello/$‘, hello), )
from django.http import HttpResponse import datetime def hello(request): return HttpResponse("Hello world") def current_datetime(request): now = datetime.datetime.now() html = "<html><body>It is now %s.</body></html>" % now return HttpResponse(html)
from django.conf.urls.defaults import * from views import hello, current_datetime urlpatterns = patterns(‘‘, (‘^hello/$‘, hello), (‘^time/$‘, current_datetime), )
urlpatterns = patterns(‘‘, (‘^hello/$‘, hello), (‘^time/$‘, current_datetime), (‘^another-time-page/$‘, current_datetime), )
urlpatterns = patterns(‘‘, # ... (r‘^time/plus/\d+/$‘, hours_ahead), # ...
(r‘^time/plus/\d{1,2}/$‘, hours_ahead),
)
from django.conf.urls.defaults import * from views import hello, current_datetime, hours_ahead urlpatterns = patterns(‘‘, (r‘^hello/$‘, hello), (r‘^time/$‘, current_datetime), (r‘^time/plus/(\d{1,2})/$‘, hours_ahead), )
from django.http import Http404, HttpResponse import datetime def hours_ahead(request, offset): try: offset = int(offset) except ValueError: raise Http404() 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)
def hours_ahead(request, offset): try: offset = int(offset) except ValueError: raise Http404() dt = datetime.datetime.now() + datetime.timedelta(hours=offset) assert False html = "<html><body>In %s hour(s), it will be %s.</body></html>" % (offset, dt) return HttpResponse(html)
标签:
原文地址:http://www.cnblogs.com/fish7/p/4374867.html