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并加载

 

相关文章:

  • 2021-11-12
  • 2022-12-23
  • 2022-12-23
  • 2022-01-27
  • 2021-11-22
  • 2021-08-30
  • 2021-12-11
  • 2022-12-23
猜你喜欢
  • 2021-12-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-09
  • 2022-12-23
相关资源
相似解决方案