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

  • 相关阅读:
    jQuery Querystring
    BCP 导出文本到文件
    ASP.NET MVC实践系列12表单处理(转)
    with(nolock) 解释 SQL
    DevServer
    静态语言、动态语言、强类型语言、弱类型语言
    @符号惹的祸
    洛谷 题解 P4198 【楼房重建】
    题解 P2668 【斗地主】
    题解 P3620 【[APIO/CTSC 2007]数据备份】
  • 原文地址:https://www.cnblogs.com/Fmaj7/p/13169898.html
Copyright © 2011-2022 走看看