zoukankan      html  css  js  c++  java
  • django __path__使用

    def get_commands():
        """
        Returns a dictionary mapping command names to their callback applications.
    
        This works by looking for a management.commands package in django.core, and
        in each installed application -- if a commands package exists, all commands
        in that package are registered.
    
        Core commands are always included. If a settings module has been
        specified, user-defined commands will also be included.
    
        The dictionary is in the format {command_name: app_name}. Key-value
        pairs from this dictionary can then be used in calls to
        load_command_class(app_name, command_name)
    
        If a specific version of a command must be loaded (e.g., with the
        startapp command), the instantiated module can be placed in the
        dictionary in place of the application name.
    
        The dictionary is cached on the first call and reused on subsequent
        calls.
        """
        commands = {name: 'django.core' for name in find_commands(upath(__path__[0]))}
    
        if not settings.configured:
            return commands
    
        for app_config in reversed(list(apps.get_app_configs())):
            path = os.path.join(app_config.path, 'management')
            commands.update({name: app_config.name for name in find_commands(path)})
    
        return commands
    

      说明:只有在__init__.py才能使用__path__,此对象表示当前目录路径,如下:

    ['C:\Users\Administrator\Envs\gz_monitor\lib\site-packages\django']
    ['E:\Mypj\monitor\apps\flowmgr']

  • 相关阅读:
    2019 SDN上机第5次作业
    iOS 多线程
    安装pygame
    五分钟学会ios反编译
    反编译ipa包
    Flutter 混合开发(一)
    iOS开发-block异步实现return
    Mac下Anaconda的安装和使用
    挣值分析
    【PMP】挣值分析
  • 原文地址:https://www.cnblogs.com/Fmaj7/p/13169898.html
Copyright © 2011-2022 走看看