本文介绍了如何使用Django中的manage.py列出所有安装的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
一些 manage.py
命令将Django应用程序作为参数。有时我想使用这些命令,但不记得应用程序的名称。有没有办法让manage.py提供一个这样的列表?
Some manage.py
commands take Django applications as arguments. Sometimes I want to use these commands, but can't remember the name of the application. Is there a way to get manage.py to provide a such a list?
推荐答案
没有准备好,但你可以管道:
not ready made, but you can pipe:
$ echo 'import settings; settings.INSTALLED_APPS' | ./manage.py shell
...
>>> ('django.contrib.auth', 'django.contrib.contenttypes',
'django.contrib.sessions', 'django.contrib.sites'...]
或写一个小的:
import settings
from django.core.management.base import BaseCommand
class Command(BaseCommand):
def handle(self, *args, **options):
print settings.INSTALLED_APPS
或以更通用的方式:
import settings
from django.core.management.base import BaseCommand
class Command(BaseCommand):
def handle(self, *args, **options):
print vars(settings)[args[0]]
$ ./manage.py get_settings INSTALLED_APPS
('django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions',
'django.contrib.sites', ...]
$ ./manage.py get_settings TIME_ZONE
America/Chicago
这篇关于如何使用Django中的manage.py列出所有安装的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!