Django - Static Files
Static Files is a Django app that helps with serving static content.
This tutorial is meant as a short and quick guide on how to configure your Django project to serve static based content.
To achieve this we will configure Django (via settings.py) and Apache. Our example will be based on serving static content from the folder '/opt/django/myproject/static/'.
First of all the following settings are added to the settings of your Django project.
STATIC_ROOT = '/opt/django/myproject/static/'
STATIC_URL = '/static/'
ADMIN_MEDIA_PREFIX = '/static/admin/'
TEMPLATE_CONTEXT_PROCESSORS = (
STATICFILES_FINDERS = (
TEMPLATE_LOADERS = (
INSTALLED_APPS = (
Within the Apache configuration the Alias directive is defined.
WSGIScriptAlias / /opt/django/myproject/apache/django.wsgi
Alias /static/ /opt/django/myproject/static/
In order to copy all of your static content to your STATIC_ROOT the following command is used.
python manage.py collectstatic
Note : The urls that your static files are collected from are defined via the STATICFILES_DIRS setting (from within settings.py).
If you have no requirement to collect your static files from the paths defined within STATICFILES_DIRS then,
- STATIC_ROOT should not be defined (i.e STATIC_ROOT = '' )
- STATICFILES_DIRS should be configured as the absolute path to your static files.
A good reference on this can be found here.