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/’.
Table of Contents
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.
- How to Configure a BIND Server on Ubuntu - March 15, 2018
- What is a BGP Confederation? - March 6, 2018
- Cisco – What is BGP ORF (Outbound Route Filtering)? - March 5, 2018
Want to become a Django expert?
Here is our hand-picked selection of the best courses you can find online:
The Complete Web Development Bootcamp course
Django Practical Guide course
Django Full Stack Developer Bootcamp
and our recommended certification practice exams:
AlphaPrep Practice Tests - Free Trial