Djang啟動時,且在讀取項目中路由之前執行某個py文件 在任意app的apps.py中的Config類中定義ready方法,並調用autodiscover_modules from django.apps import AppConfig from djngo.utils.module_loading import autodiscover_modules class StarkConfig(AppConfig) name = 'stark' def read(self) autodiscover_modules('stark') 程序啟動時,會先去每個app中找stark.py並加載