【发布时间】:2023-03-16 21:48:01
【问题描述】:
我有许多类,我希望在这些类上运行装饰器函数。据我所知,装饰器仅在将类/函数/它们标签的任何内容加载到代码中时运行。
例如
def decorator(cls):
print("Decorator executed")
return cls
@decorator
class Example:
pass
Example()
如何在 django 应用程序启动时触发装饰器标签的所有类上的装饰器函数,而不必单独加载每个类? (或者不知道装饰器标记的类)
【问题讨论】:
-
装饰器不应该这样工作,也许要重新考虑你想要实现的目标。
标签: python django python-3.x python-decorators