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.

Rick Donato

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