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

  • 相关阅读:
    方法
    成员变量和局部变量
    带参数的方法
    包名规范
    String
    导包
    java基础(十二章)
    java基础(十一章)
    java基础(九章)
    java基础(八章)
  • 原文地址:https://www.cnblogs.com/Fmaj7/p/13169898.html
Copyright © 2011-2022 走看看