@
Neo10373 哈哈,谢谢老哥,这个方法是可以,但是我想使用 Viewset 和 Mixin 带给我的便利,那个 permission 的我自己写过一个装饰器可以对 create 和 retrieve 方法管用,但是不知道为什么写成 authentication 那样就不行了啊
```[python]
from functools import update_wrapper
def auth_wrapper(*authentications, validate_auth=True):
def decorator(func):
def wrapper(self, request, *args, **kwargs):
self.authentication_classes=authentications
print(self.authentication_classes)
if validate_auth:
print(f'request1:{request.user}')
self.perform_authentication(request)
print(f'request2:{request._user}')
# print(type(self.perform_authentication(request)))
print('进来了')
return func(self, request, *args, **kwargs)
return update_wrapper(wrapper, func)
return decorator
def permission_wrapper(*permissions, validate_perm=True):
def decorator(func):
def wapper(self, request, *args, **kwargs):
self.permission_classes=permissions
if validate_perm:
self.check_permissions(request)
return func(self, request, *args, **kwargs)
return update_wrapper(wapper, func)
return decorator
```