django __path__使用
Posted fmaj7
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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‘]
以上是关于django __path__使用的主要内容,如果未能解决你的问题,请参考以下文章