No reference decorator:
When invoked with no parameters decorator, the outer layer does not need to pass parameters.
It applies, for example:
- Increase uptime statistics function is a function
- Increase login authentication function is a function before running
There are parameters decorator:
When calling parameters have decorator, passing them one or more parameters.
It applies, for example:
- verify that the user types
def user_auth(user_group): def wrapper(func): def inner(*args, **kwargs): if user_group == 'SVIP': print('Dear SVIP') res = func(*args, **kwargs) return res elif user_group == 'General': res = func(*args, **kwargs) return res else: print('Please login first!') login() return inner return wrapper @user_auth(user_group='SVIP') def welcome(): print('Welcome to the index') welcome()