import functools
# Decorator , Used to authenticate whether the user logs in
def user_logging(func):
@functools.wraps(func)
def deco(*args,**kwargs):
user_id = args[0].COOKIES.get('user_id')
if user_id:
user = User.objects.filter(id = user_id).first()
args[0].context = {'user':user}
return func(args[0])
else:
return redirect('login')
return deco
adopt request.context['user'] Get the login information of the current user