Django学习-3-请求流程

Django请求生命周期
    -> URL对应关系(匹配) -> 视图函数 -> 返回用户字符串
    -> URL对应关系(匹配) -> 视图函数 -> 打开一个HTML文件,读取内容

1.浏览器客户端请求首先到达项目名文件夹下的urls.py

urlpatterns = [

    url(r'^app1/', include("app1.urls")),
    url(r'^app2/', include("app2.urls")),
   
]

2.经过路由分发会到app下的urls.py

urlpatterns = [

    url(r'^admin/', admin.site.urls),
    url(r'^read/', views.read),
    url(r'^login', views.login),
    url(r'^orm', views.orm),
    url(r'^home', views.home),
    url(r'^register', views.Register.as_view()),
    url(r'^father', views.father),
    url(r'^child', views.child),
    url(r'^tpl', views.tpl),
    url(r'^user_list', views.user_list),
    url(r'^aaa-(?P<uid>\d+)-(?P<pid>\d+).html', views.aaa),
]

3.然后到处理函数

def read(request):
    return HttpResponse("<h1>readding a book!!</h1>")
def read(request):
    return render(request,"read.html")
def read(request):
    return redirect("/cmdb/read")

 

4.处理完成返回静态HTML页面到用户浏览器显示





posted @ 2017-11-08 21:07  前路~  阅读(151)  评论(0编辑  收藏  举报