请求响应Http
1. 发送Http请求@H_502_3@
2. 服务器接受后,根据请求头中的url在路由关系表(urls.py)中进行匹配@H_502_3@
3. 匹配成功后,执行指定的views函数
URL ----> 函数 =======》FBV@H_502_3@
URL ----> 类 =======》CBV
根据函数(FBV)或者类(CBV)进行分发
4. 业务处理
响应头赋值:
def post(self, req): ret = HttpResponse('cbv.post') ret['h1'] = 'v1' ret['h2'] = 'v4' ret.set_cookie('c1','v2') ret.set_cookie('c2','v3') ''' 响应头: h1=v1 h2=v4 cookies:c1=v2;c2=v3 响应体: cbv.post '''
@H_502_3@
CBV示例代码:
--------------------------views.py----------------------- class CBV(View): def dispatch(self, request, *args, **kwargs): res = super(CBV, self).dispatch(request, **kwargs) return res def get(self, req): return render(req, 'index.html') def post(self, req): ret = HttpResponse('cbv.post') ret['h1'] = 'v1' ret['h2'] = 'v4' ret.set_cookie('c1','v2') ret.set_cookie('c2','v3') ''' 响应头: h1=v1 h2=v4 cookies:c1=v2;c2=v3 响应体: cbv.post ''' return ret --------------------------urls.py------------------------------ url(r'^manage/student/$', views.CBV.as_view(), name='student'),---------------------------index.html-------------------------- <body> <input type=text name='user'> <input type='submit' value='提交'> </body>
@H_502_3@
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。