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

python基础(二十)

时间:2016-12-23 13:55:09      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:参数   redirect   form   hunk   函数   请求   pytho   home   include   

1、Django请求的生命周期
路由系统 -> 试图函数(获取模板+数据=》渲染) -> 字符串返回给用户

2、路由系统
/index/ -> 函数或类.as_view()
/detail/(\d+) -> 函数(参数) 或 类.as_view()(参数)
/detail/(?P<nid>\d+) -> 函数(参数) 或 类.as_view()(参数)
/detail/ -> include("app01.urls")
/detail/ name=‘a1‘ -> include("app01.urls")
- 视图中:reverse
- 模板中:{% url "a1" %}

3、视图
FBV:函数
def index(request,*args,**kwargs):
..

CBV:类
class Home(views.View):

def get(self,reqeust,*args,**kwargs):
..

获取用户请求中的数据:
request.POST.get
request.GET.get
reqeust.FILES.get()

# checkbox,
........getlist()

request.path_info


文件对象 = reqeust.FILES.get()
文件对象.name
文件对象.size
文件对象.chunks()

# <form 特殊的设置></form>


给用户返回数据:
render(request, "模板的文件的路径", {‘k1‘: [1,2,3,4],"k2": {‘name‘: ‘张扬‘,‘age‘: 73}})
redirect("URL")
HttpResponse(字符串)


python基础(二十)

标签:参数   redirect   form   hunk   函数   请求   pytho   home   include   

原文地址:http://www.cnblogs.com/chaishao/p/6214232.html

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