码迷,mamicode.com
首页 > 编程语言 > 详细

python--django之视图函数

时间:2017-11-10 01:47:08      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:view   htm   pat   method   rect   log   函数   login   用户   

 

 

1.视图函数中的两个对象

1.1.request(请求对象):
  request.GET {} get请求数据
  request.POST {} post请求数据
  request.POST.getlist()
  request.method 请求方式
  request.path 请求路径
  request.get_full_path() 请求全路径


1.2.response(响应对象):

  Httpresponse()

  1.2.1.render(request,template_name,context)

          template:模板
          context:上下文对象

  1.2.2.redirect(跳转,重定向)

    redirect("/路径/")

   模拟用户点击submit请求:
              请求url:http://127.0.0.1:8000/login/
    分为三个步骤:
    (1)请求url:/login/ POST
    (2)url(r‘^login/‘, app01_views.login,name="LOGIN"),
    (3)login(request): 验证 , if 成功: redirect("/index/")

  重定向请求:
       请求路径:http://127.0.0.1:8000/index/
    (1) /index/ get
         (2) url(r‘^index/‘, app01_views.index,name="index")
         (3) index(request) : 取出数据库数据,渲染到index.html页面

       用户看到的是:渲染的index.html页面

1.3.redirect与render的区别: redirect两次请求 render一次请求

 

python--django之视图函数

标签:view   htm   pat   method   rect   log   函数   login   用户   

原文地址:http://www.cnblogs.com/yxwang/p/7812122.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!