How to list all installed apps with manage.py in Django?

后端 未结 1 1710
南旧
南旧 2020-12-18 04:00

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

相关标签:
1条回答
  • 2020-12-18 04:46

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

    or write a small custom command:

    import settings
    from django.core.management.base import BaseCommand
    class Command(BaseCommand):
        def handle(self, *args, **options):
            print settings.INSTALLED_APPS
    

    or in a more generic way:

    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 
    
    0 讨论(0)
提交回复
热议问题