Day31.登录认证装饰器
1.登录认证装饰器_代码导入及执行流程
2.登录认证装饰器_公共方法common.py
'''公共方法''' def auth(role): # todo 先判断进来的是否是管理员,老师,学生 # todo 登录装饰器 from core import admin, student, teacher def login_auth(func): def inner(*args, **kwargs): if role == 'admin': if admin.admin_info['user']: res = func(*args, **kwargs) return res else: admin.login() elif role == 'student': if student.student_info['user']: res = func(*args, **kwargs) return res else: admin.login() elif role == 'teacher': if teacher.teacher_info['user']: res = func(*args, **kwargs) return res else: admin.login() else: print('当前视图没有权限') return inner return login_auth