1.自制装饰器
def wrapper_logined(func):
def inner(request,*args,**kwargs):
#如果有session放行
if request.session.get('logined'):
return func(request,*args,**kwargs)
# 问题:当访问 添加店铺时,因为权限被限制,跳转到登陆页面,但登录完没有跳转到添加店铺的页面
else: #如果没有session跳转到登陆,同时用cookie记住所访问的路径
response = render(request,'store/login.html')
full_path = request.get_full_path() #获取没登录时想要跳转页面的路径
response.set_cookie('full_path',full_path) #记住路径
return response
return inner
使用
2.用户认证系统自带的装饰器
导入
使用固定参数