码迷,mamicode.com
首页 > 其他好文 > 详细

django

时间:2018-06-04 22:33:13      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:nbsp   ati   col   IV   port   定制   sel   dispatch   self   

django的 CBV

定制dispatch,定制响应头,定制cookie

 1 from django.shortcuts import render,HttpResponse
 2 from django.views import View
 3 # Create your views here.
 4 class Myindex(View):
 5     #定制dispatch
 6     def dispatch(self, request, *args, **kwargs):
 7         result=super(Myindex,self).dispatch(request,*args,**kwargs)
 8         return  result
 9     def get(self,request):
10         return  render(request,index.html)
11     def post(self,request):
12         #定制响应头
13         ret=HttpResponse(saoka)
14         ret[h1]=v1
15         ret[h2]=v3
16         #设置cookie
17         ret.set_cookie(c1,v2)
18         ret.set_cookie(c2,v3)
19         return  ret

 django的 静态文件路径的设置

STATICFILES_DIRS=[
os.path.join(BASE_DIR,‘static‘)
]

django

标签:nbsp   ati   col   IV   port   定制   sel   dispatch   self   

原文地址:https://www.cnblogs.com/hexintong/p/9135799.html

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