Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a quick way to tell if an app is in Django's INSTALLED_APPS?

Tags:

python

django

I'm writing a quick Django module and want to check for another module. Is there's a shortcut to check if another module is in the INSTALLED_APPS list in Django's settings?

like image 853
Gabriel Hurley Avatar asked Dec 22 '22 09:12

Gabriel Hurley


2 Answers

from settings import INSTALLED_APPS
if 'appname' in INSTALLED_APPS:
    print 'we have app'

And this way is somewhat how Django itself does. Also check the load_app method on the linked page.

like image 173
inerte Avatar answered Dec 28 '22 23:12

inerte


Django contains a registry of installed applications that you can use for this purpose:

>>> from django.apps import apps
>>> apps.is_installed("django.contrib.admin")
True
like image 42
Eugene Yarmash Avatar answered Dec 29 '22 01:12

Eugene Yarmash