1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
__author__ = 'Afreto' __email__ = 'kongandmarx@163.com' __date__ = '2018/5/11'
from django.http import HttpResponseRedirect,HttpResponse
def decorator_test(view): def decorator(request,*args,**kwargs): token = request.COOKIES.get('token',False) print(token,type(token)) try: if 'token' in request.COOKIES: return view(request,*args,**kwargs) else: response = HttpResponseRedirect(request.build_absolute_uri()) response.set_cookie('token', 1) return response except ValueError: pass return auth_fail_handler(request) return decorator
if __name__ == '__main__': pass
|