django中使用装饰器装饰路由
def deco(func): def _deco(request): reqFun=None try: loginbean = request.session['loginbean'] if loginbean == None: return HttpResponse("<script>alert('登录过期,请重新登录');location.href='/';</script>") if loginbean['role'] == 3: reqFun = func(request,loginbean) return reqFun # return render(request, 'works/showCreateWorks.html', {'loginbean': loginbean}) else: return HttpResponse("<script>alert('您无权限进入');location.href='/';</script>") except Exception as err: print(err) return HttpResponse("<script>alert('请登录');location.href='/';</script>") return _deco @deco def myworks(request,loginbean): return render(request, 'works/myworks.html',{'loginbean':loginbean}) @deco def showcreateworks(request,loginbean): return render(request, 'works/showCreateWorks.html',{'loginbean':loginbean})