首页 > 代码库 > 装饰器做权限认证

装饰器做权限认证

#!/usr/bin/env python
#_*_coding:utf-8_*_
from django.shortcuts import render,HttpResponse

allow_list = [admin]

def cron_allow(request,**kwargs):
    if request.user.username in allow_list:
        return True
    else:
        return False
def check_cron_permission(fun):
    def wapper(request, *args, **kwargs):
        if cron_allow(request, **kwargs):
            return fun(request, *args, **kwargs)
        return render(request, forbiden.html, locals())
    return wapper

 

装饰器的介绍参加  以前的文章

装饰器做权限认证