视图Helloworld

 

from django.http import HttpResponse

def hello(request):
return HttpResponse("Hello world")

 

 

路由文件

 

urls.py
from django.conf.urls.defaults import*
 from mysite.views import hello
 
# Uncomment the next two lines to enable the admin:
#
from django.contrib import admin
#
admin.autodiscover()

urlpatterns
= patterns('',
# Example:
# (r'^mysite/', include('mysite.foo.urls')),

# Uncomment the admin/doc line below and add 'django.contrib.admindocs'
# to INSTALLED_APPS to enable admin documentation:
# (r'^admin/doc/', include('django.contrib.admindocs.urls')),

# Uncomment the next line to enable the admin:
# (r'^admin/', include(admin.site.urls)),
('^hello/$', hello),
)

 

动态路由

urlpatterns = patterns('',
# ...
(r'^time/plus/\d+/$', hours_ahead),
# ...
)

 

views.py
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)

 

 

相关文章:

  • 2022-12-23
  • 2021-09-27
  • 2021-08-12
  • 2021-09-18
  • 2022-01-03
  • 2021-11-14
  • 2021-09-13
猜你喜欢
  • 2019-03-16
  • 2021-09-24
  • 2022-12-23
  • 2022-01-23
  • 2022-12-23
  • 2021-07-29
  • 2021-08-07
相关资源
相似解决方案