Installation
Install django-bower package:
pip install django-bower
Add django-bower to 
INSTALLED_APPS in your settings:
'djangobower',
Add staticfinder to 
STATICFILES_FINDERS:
'djangobower.finders.BowerFinder',
Specifie path to components root (you need to use absolute path):
BOWER_COMPONENTS_ROOT = '/PROJECT_ROOT/components/'
If you need, you can manually set path to bower
BOWER_PATH = '/usr/bin/bower'
You can see example settings file in 
example project.
 
Usage
Specifie 
BOWER_INSTALLED_APPS in settings, like:
BOWER_INSTALLED_APPS = (
    'jquery#1.9',
    'underscore',
)
Download bower packages with management command:
./manage.py bower install
Add scripts in template, like:
{% load static %}
<script type="text/javascript" src='{% static 'jquery/jquery.js' %}'></script>
In production you need to call 
bower install before 
collectstatic:
./manage.py bower install
./manage.py collectstatic
If you need to pass arguments to bower, like 
–allow-root, use:
./manage.py bower install -- --allow-root
You can use 
bower freeze to receive 
BOWER_INSTALLED_APPS with fixed current versions:
./manage.py bower freeze
You can call bower commands like 
info and 
update with:
./manage.py bower info backbone
./manage.py bower update
 
No comments:
Post a Comment