#登录验证装饰器 def auth(func): def inner(request,*args,**kwargs): username1 = request.session.get(‘username‘) username2 = request.COOKIES.get(‘username‘) if not username1 or not username2: return redirect(‘/login‘) return func(request, *args,**kwargs) return inner
装饰器使用
@auth def index(request): return render_to_response(‘index.html‘,locals())
时间: 2024-10-25 16:26:52