view: CBV模式

url.py文件定义url的方式跟以前的不一样
path("/",view.index.as_view())

view.py
from django.views import View
from django.utils.decorators import method_decorator

继承登入认证模块来进行验证 和view模块

class index(LoginRequiredMixin,View):
def get(request):
pass
def post(request):
pass

def outer(func):
def inner(request, *args, **kwargs):
print(request.method)
return func(request, *args, **kwargs)
return inner

用登入装饰器来装饰一个类,将验证写在outer函数

@method_decorator(outer, name='dispatch')
class index2(View):
def get(request):
pass
@method_decorator(outer)
def dispatch(self, request, *args, **kwargs): #dispach函数会分发到get或者post函数
ret = super(Login, self).dispatch(request, *args, **kwargs)
return ret

转载于:https://www.cnblogs.com/harveyjie/p/9765865.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值