Search code examples
djangodjango-viewsdjango-apps

Adapt a view if an app is installed with Django


I have a web app with a project that works alone (it's index, login.. pages).

I would need to change the index page if a new app is installed (e.g: add a link, a table in the template with my app models..). Have it dynamic.

The removal of the app must let the project intact and just remove the link.

How can I do that? Is it possible?


Solution

  • 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 %}