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

191112Django fbv和cbv

时间:2019-11-22 01:07:02      阅读:59      评论:0      收藏:0      [点我收藏+]

标签:war   def   pre   rgs   end   views   pos   dispatch   cbv   

  • cbv:类、base、view
  • fbc:函数、base、view
from django.contrib import admin
from django.urls import path
from app import views

urlpatterns = [
    path('fbv/', views.fbv),
    path('cbv/', views.CBV.as_view()),
]
from django.shortcuts import render,redirect,HttpResponse
from django.views import View

def fbv(request):
    return HttpResponse("FBV")

class CBV(View):
    def dispatch(self, request, *args, **kwargs):
        result = super(CBV,self).dispatch(request, *args, **kwargs)
        return result
    def get(self,request):
        return render(request,'cbv.html')
        # return HttpResponse("CBV.GET")
    def post(self,requset):
        ret = HttpResponse("CBV.POST")
        ret['h1'] = 'v1'  #添加响应头
        ret.set_cookie('c1','v2')  #添加cookie
        return ret

191112Django fbv和cbv

标签:war   def   pre   rgs   end   views   pos   dispatch   cbv   

原文地址:https://www.cnblogs.com/L-dongf/p/11909344.html

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