• django APP注册 pupulate函数


     1     def populate(self, installed_apps=None):
     2         """
     3         Loads application configurations and models.
     4 
     5         This method imports each application module and then each model module.
     6 
     7         It is thread safe and idempotent, but not reentrant.
     8         """
     9         if self.ready:
    10             return
    11 
    12         # populate() might be called by two threads in parallel on servers
    13         # that create threads before initializing the WSGI callable.
    14         with self._lock:
    15             if self.ready:
    16                 return
    17 
    18             # app_config should be pristine, otherwise the code below won't
    19             # guarantee that the order matches the order in INSTALLED_APPS.
    20             if self.app_configs:
    21                 raise RuntimeError("populate() isn't reentrant")
    22 
    23             # Phase 1: initialize app configs and import app modules.
    24             for entry in installed_apps:
    25                 if isinstance(entry, AppConfig):
    26                     app_config = entry
    27                 else:
    28                     app_config = AppConfig.create(entry)
    29                 if app_config.label in self.app_configs:
    30                     raise ImproperlyConfigured(
    31                         "Application labels aren't unique, "
    32                         "duplicates: %s" % app_config.label)
    33 
    34                 self.app_configs[app_config.label] = app_config
    35                 app_config.apps = self
    36 
    37             # Check for duplicate app names.
    38             counts = Counter(
    39                 app_config.name for app_config in self.app_configs.values())
    40             duplicates = [
    41                 name for name, count in counts.most_common() if count > 1]
    42             if duplicates:
    43                 raise ImproperlyConfigured(
    44                     "Application names aren't unique, "
    45                     "duplicates: %s" % ", ".join(duplicates))
    46 
    47             self.apps_ready = True
    48 
    49             # Phase 2: import models modules.
    50             for app_config in self.app_configs.values():
    51                 app_config.import_models()
    52 
    53             self.clear_cache()
    54 
    55             self.models_ready = True
    56 
    57             # Phase 3: run ready() methods of app configs.
    58             for app_config in self.get_app_configs(): #源码无try
    59                 try:
    60                     app_config.ready()
    61                 except:
    62                     pass
    63 
    64             self.ready = True

    celery任务启动时,admin注册出错,需做修改。

  • 相关阅读:
    numpy计算路线距离
    WebApi安全性 使用TOKEN+签名验证
    从SQL查询分析器中读取EXCEL中的内容
    Autofac应用总结
    Visual Studio提示“无法启动IIS Express Web服务器”的解决方法
    架构 : 三层架构、MVC、MVP、MVVM
    Asp.Net MVC :路由器
    myeclipse10安装egit和使用
    myeclipse10.7安装git插件
    SQLite之C#连接SQLite
  • 原文地址:https://www.cnblogs.com/Fmaj7/p/13516042.html
Copyright © 2020-2023  润新知