How to set up Django static files in production and local

For newbies it can be a daunting experience trying to get your static files upright for production. In this 3 step formular you should be guided with ease with django static files; NB: This post assumes you have already setup your template directory and database url (You have been working local with no issues and ready to take your website live).

With that said; Setting up your django static files for production;

  • Step 1
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '='

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False

ALLOWED_HOSTS = ['yoururl.com', '127.0.0.1']

In production never expose your SECRET_KEY, set DEBUG to False and enter your url in the ALLOWED_HOSTS list.

  • Step 2
STATIC_URL = '/static/'
STATIC_ROOT = '/your/url/to/static'

You should only have these two(2) static variables. Dispose off your STATICFILES_DIRS at this point.

BONUS Step

For quick loading of your static files you can also pip install whitenoise and set whitenoise in your MIDDLEWARE like below;

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',

I trust this info was helpful for your setup unto your live server.

If you need assistance with your projects feel free to email me at info@airgad.com or whatsapp Jesse stay safe!