zoukankan      html  css  js  c++  java
  • [python]django学习笔记 二

    视图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)
  • 相关阅读:
    【JavaScript】--ajax
    【Django】--Models 和ORM以及admin配置
    【Django】--基础知识
    【jQuery】--图片轮播
    双系统 windows引导项添加
    LVM
    linux安全加固
    oracle 11G 配置侦听文件
    LVM
    《virtual san 最佳实践》节选 Virtual SAN的发展与现状
  • 原文地址:https://www.cnblogs.com/bluefrog/p/1922641.html
Copyright © 2011-2022 走看看