装潢师看起来是这样的:
def allowed_states(allowed=[]):
def decorator(func):
def wrapper(self, request, *args, **kwargs):
print(func)
result = func(self, request, *args, **kwargs)
return result
return wrapper
return decorator
@swagger_auto_schema(
operation_id="my_api",
responses={
status.HTTP_204_NO_CONTENT: "",
}
)
@action(detail=True, methods=["DELETE"])
@allowed_states(allowed=["state1", "state2"])
def my_api(self, request, *args, **kwargs):
# do some stuff here
当我的
@allowed_states
装潢师被移除,呼叫工作正常。当我将它添加回来时,Django framework出现404错误,说它找不到要为此调用执行的url模式。
我试着移除
self
从
wrapper
func
也可以调用)。
此外,我还尝试更改函数调用上方的decorators顺序。
两个都没用。
Using the URLconf defined in
<code>my_project.urls</code>,
Django tried these URL patterns, in this order:
(然后是url模式在
my_project.urls
)