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 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/'





Apache Configuration

 Within the Apache configuration the Alias directive is defined.

<VirtualHost *:80>
        WSGIScriptAlias / /opt/django/myproject/apache/django.wsgi
        Alias /static/ /opt/django/myproject/static/

Collect Files

In order to copy all of your static content to your STATIC_ROOT the following command is used.

python collectstatic

Note : The urls that your static files are collected from are defined via the STATICFILES_DIRS setting (from within


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.

About the Author


R Donato

Rick Donato is the Founder and Chief Editor of He currently works as an SDN/NFV Solutions Architect and has a keen interest in automation and the cloud.

You can find Rick on Twitter @f3lix001