3

I'm completely new for django and I'd want to list the apps of a django project, for example:

FeinCMS

I know that startapp creates the directory structure for an app. I wonder if there is either a function or a file to get the app list.

For example taking FeinCMS as an example, the repo contains:

feincms
├── AUTHORS
├── CHANGELOG.rst
├── CONTRIBUTING.rst
├── docs
│   ├── admin.rst
│   ├── advanced
│   ├── conf.py
│   ├── contenttypes.rst
│   ├── contributing.rst
│   ├── deprecation.rst
│   ├── extensions.rst
│   ├── faq.rst
│   ├── images
│   ├── index.rst
│   ├── installation.rst
│   ├── integration.rst
│   ├── Makefile
│   ├── medialibrary.rst
│   ├── migrations.rst
│   ├── page.rst
│   ├── releases
│   ├── settings.rst
│   ├── templatetags.rst
│   └── versioning.rst
├── feincms
│   ├── admin
│   ├── apps.py
│   ├── content
│   ├── contents.py
│   ├── context_processors.py
│   ├── contrib
│   ├── default_settings.py
│   ├── extensions
│   ├── __init__.py
│   ├── _internal.py
│   ├── locale
│   ├── management
│   ├── models.py
│   ├── module
│   ├── shortcuts.py
│   ├── signals.py
│   ├── static
│   ├── templates
│   ├── templatetags
│   ├── translations.py
│   ├── urls.py
│   ├── utils
│   └── views
├── LICENSE
├── MANIFEST.in
├── README.rst
├── setup.cfg
├── setup.py
└── tests
    ├── cov.sh
    ├── manage.py
    ├── requirements.txt
    ├── testapp
    └── tox.ini

How can I use django to list the apps in the repo?

sebelk
  • 565
  • 1
  • 6
  • 16
  • Check [this](https://stackoverflow.com/questions/4111244/get-a-list-of-all-installed-applications-in-django-and-their-attributes) as put forward by @nttaylor in comments section of the **accepted** solution. – carla Dec 07 '22 at 04:38

2 Answers2

3

settings.INSTALLED_APPS is the list of apps. You can start a django shell (manage.py shell) to query the settings:

from django.conf import settings
print(settings.INSTALLED_APPS)

>>> ['user', 'django.contrib.auth', 'django.contrib.sites', ...]
dirkgroten
  • 20,112
  • 2
  • 29
  • 42
  • It's a nice answer, however, this the case when you are developing a project. But how can I load an existing project in django and list its apps? I will clarify my question. – sebelk Jun 22 '18 at 20:15
  • You can't. You need to create an app that uses the FeinCMS and then run it (in the shell). The testapp in the tests directory will allow you to do that without having to create an app yourself. – dirkgroten Jun 23 '18 at 14:44
3

Query django.apps ...

from django.apps import apps
for app in apps.get_app_configs():
       print(app, app.name, app.label)

Results in ...

<ContentTypesConfig: contenttypes> django.contrib.contenttypes contenttypes
<AdminConfig: admin> django.contrib.admin admin
Patti
  • 186
  • 3
  • 7
  • this is a much better approach because often you care about the app label (such as running migrate or makemigrations) – Micah Smith Jul 20 '23 at 02:46