from django.apps import AppConfig class ApiConfig(AppConfig): default_auto_field = 'django.db.models.BigAutoField' name = 'api' def ready(self): import os if os.environ.get('RUN_MAIN') or os.environ.get('SERVER_GATEWAY'): # 检测开发环境,避免重复启用定时任务 from .scheduler import start_scheduler start_scheduler()