Django - Dynamically include JS/CSS based on installed apps -
does know way adjust included js/css resources in template based on apps you've installed?
let's have basic feature in app x using template.html, , requires foo.js provided in static files app.
what i'd way of saying additional , optional app y can register bar.js included in template.html , provides advanced functionality.
ideally, should tied in on feature level - register both foo.js , bar.js provide feature a , in template indicate want static content a.
you can follow django admin framework approach. in base template have section style , javascript. based on condition can insert new files.
for example:
define these 2 blocks in base template
{% block extracss %}{% endblock %} {% block extrajs %}{% endblock %} if want add js or css based on condition, can add check inside
{% block extracss %} {% if new_app_installed %} # insert css {% else %} # default {% endif %} {% endblock %} you can check if plugin app installed , pass context variable view template.
from django.conf import settings if "new_app" in settings.installed_apps: is_new_app_installed = true
Comments
Post a Comment