8π
I followed this blog post to setup my django bower project:
Project structure:
|-root
|-app
|-assets
|-static
|-templates
|settings.py
|urls.py
|views.py
|wsgi.py
|manage.py
|bower.json
|.bowerrc
My .bowerrc
:
{
"directory": "app/static/bower_components"
}
And I user bower components like this:
<script src="{{ STATIC_URL }}bower_components/angular/angular.js"></script>
My settings.py
:
STATIC_URL = '/static/'
STATIC_ROOT = join(BASE_DIR, 'assets')
STATICFILES_DIRS = [join(BASE_DIR, 'static')]
Also urls.py
:
urlpatterns += patterns('',
(r'^static/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.STATIC_ROOT}),)
4π
There is no need for apps like django-bower, or other specialized tools that take up server resources, slow build time, and greatly limit the usefulness of bower. Especially, when you have nested django apps with their own bower dependancies.
You can check out my tutorial on how to seamlessly integrate Django + Bower + Heroku here. Although this tutorial targets heroku, the methodology applies to any deployment scenario.
2π
There is no recommended way β it depends on your project. If you are using bower, node for more than the django project, it might make sense to place it in your project root (above django) so that it may be reused elsewhere.
If itβs purely for djangoβs static files, then it might make sense to place it in a src/
outside of the staticfiles
system which builds to the static directory which is exported via collectstatic.
- Django channels and socket.io-client
- Django models β assign id instead of object
- Django redirect() with anchor (#) parameters
- How does this Man-In-The-Middle attack work?
2π
You should list the installed bower packages in the settings.py using key BOWER_INSTALLED_APPS.
Now, in your development server, using the {% static %} templatetag finds them from their installed directory. In production server, the collectstatic will collect the correct static files from the installed directory (bower_components).
See more: http://django-bower.readthedocs.org/en/latest/usage.html
- Django testing: Got an error creating the test database: database "database_name" already exists
- Convert Python None to JavaScript null
- Django queryset exclude() with multiple related field clauses
- PIL β libjpeg.so.8: cannot open shared object file: No such file or directory
2π
If youβre afraid of the bower.json being included, the collectstatic
command has an --ignore
option that you can use to exclude whatever you want.