码迷,mamicode.com
首页 > 其他好文 > 详细

django __path__使用

时间:2020-06-20 18:37:01      阅读:74      评论:0      收藏:0      [点我收藏+]

标签:ppi   and   pps   lib   def   from   set   work   spec   

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‘]

django __path__使用

标签:ppi   and   pps   lib   def   from   set   work   spec   

原文地址:https://www.cnblogs.com/Fmaj7/p/13169898.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!