保持信号组织:
__init__.py
default_app_config = 'posts.apps.PostsConfig'
apps.py
from django.apps import AppConfig
class PostsConfig(AppConfig):
name = 'posts'
def ready(self):
import posts.signals
如何确保ready()
或import posts.signals
仅运行一次?
答案 0 :(得分:0)
from django.apps import AppConfig
class PostsConfig(AppConfig):
name = 'posts'
ready_has_run = False
def ready(self):
if self.ready_has_run:
return
import posts.signals
self.ready_has_run = True