Staticloader is a simple Django app which provides template tags for loading JavaScript and CSS files into the template.
Install using pip:
pip install git+git://github.com/izderic/django-staticloader.git
Add "staticloader" to your INSTALLED_APPS setting like this:
INSTALLED_APPS = ( ... 'staticloader', )
Define dictionaries
JS_FILES
andCSS_FILES
in your Django settings file like this:# settings.py # ============ JS_FILES = { 'myCustomScript': 'js/myCustomScript.js', 'exampleScript': 'js/exampleScript.js', ... } CSS_FILES = { 'style': 'css/style.css', 'otherStyle': 'css/otherStyle.css', ... }
In your template add
{% load staticloader_tags %}
on the top.Use template tags
{% loadjs %}
and{% loadcss %}
to include the files defined in settings.{% loadcss "style" "otherStyle" %} {% loadjs "myCustomScript" "exampleScript" %}