首页 > 其他 > 详细

django

时间:2018-06-04 21:56:08      阅读:182      评论:0      收藏:0      [点我收藏+]

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!