Adapt view if application is installed with Django

I have a website with a project that works alone (this is an index, login page).

I need to adapt the index for an example if my new application is installed (for example: add a link, a table to the template with application models ..).

Uninstalling the application should leave the project intact

How can i do this? Is it possible?

+4
source share
3 answers
def my_view(request): from django.conf import settings app_installed = 'app_name' in settings.INSTALLED_APPS return render_to_response(template_name, {'app_installed': app_installed}) 

template:

 {% if app_installed %} ... {% endif %} 
+5
source

You can use the django application registry :

 In [1]: from django.apps import apps In [2]: apps.is_installed("django.contrib.admin") Out[2]: True 

An application can be included using the Python dot path for its package or application configuration class (preferred). Just checking if "app_name" is in settings.INSTALLED_APPS will not be done in the latter case.

+4
source

Or use a custom context handler.

In installed_apps.py

 from django.conf import settings def installed_apps(request): return { 'app_installed' : 'app_name' in settings.INSTALLED_APPS } 

In settings.py :

 TEMPLATE_CONTEXT_PROCESSORS = ( ... 'installed_apps.installed_apps' ) 
+3
source

All Articles