Deploying Django Projects

Deploy Django applications on Skyversal in seconds using Gunicorn. Guide on collectstatic, database migrations, and environment variables.

Deploying Django Projects

With its admin panel, ORM, and rich ecosystem, Django is the web's "batteries-included" framework. Skyversal automatically runs your Django projects with Gunicorn following production best practices.

Read Time: 6 Minutes
Server: Gunicorn
Recommended DB: PostgreSQL

What you'll learn in this guide

  • Required dependencies and file structure
  • Static file management with WhiteNoise (collectstatic)
  • Database migration commands (migrate)
  • Gunicorn and production settings (ALLOWED_HOSTS)

1. Required Dependencies (requirements.txt)

To ensure your application runs smoothly in production, make sure your requirements.txt includes these essential dependencies:

requirements.txt
Django==4.2.0
gunicorn==21.2.0 # Required as WSGI server
psycopg2-binary==2.9.9 # If using PostgreSQL
whitenoise==6.6.0 # For serving static files
💡
Why is Gunicorn Required?

Django's built-in python manage.py runserver is for local development only and should never be used in production. When Skyversal detects the gunicorn package, it starts your project with a multi-threaded production server.

2. Security and Environment Variables (settings.py)

Before pushing your code to GitHub, make your security settings dynamic in settings.py. Never hardcode secrets; add them as environment variables from the Skyversal panel (Settings > Environment Variables).

import
os

# SECRET_KEY should never be hardcoded
SECRET_KEY = os.getenv('SECRET_KEY', 'fallback-secret-key')

# Must always be False in production!
DEBUG = os.getenv('DEBUG', 'False') == 'True'

# Accept traffic since Nginx reverse proxy sits in front
ALLOWED_HOSTS = ['*']

3. Static Files and WhiteNoise (Critical)

When DEBUG = False, Django stops serving CSS, JS, and images. To prevent static files from returning 404 errors, you need to use WhiteNoise.

1
Add the Middleware

Add WhiteNoise to the MIDDLEWARE list in settings.py. It must come right after SecurityMiddleware!

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',
    ...
]
2
Define Static Root

Skyversal automatically runs collectstatic during the build. You need to specify the target directory for collected files.

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

4. Database and Migrations

After deploying your project on Skyversal, you'll need to create your database tables.

  1. Go to the Skyversal panel and open your project's Deploy Logs / Run Commands tab.
  2. Type python manage.py migrate in the command field and execute it.
  3. To create a superuser, python manage.py createsuperuser is interactive. Instead, you can use a custom management command that reads from environment variables, or connect directly to your Managed Database using a database client (DBeaver, etc.).

Common Errors (Troubleshooting)

ModuleNotFoundError: No module named 'django'

Fix: Your project root is missing requirements.txt or it doesn't include Django. Make sure the file is pushed to GitHub.

Static files (CSS/JS) 404 Not Found

Fix: You're running with DEBUG=False without WhiteNoise. Add the WhiteNoise settings from Step 3 to your settings.py.

OperationalError: no such table

Fix: Your database tables don't exist. Run python manage.py migrate from the panel to create them.

Application failed health check

Fix: Gunicorn couldn't start. There may be a syntax error in your code or the ALLOWED_HOSTS setting is missing. Check your deploy logs.

You're Ready! 🚀

After completing these settings, just push your code. Skyversal will have your site live with SSL via Gunicorn in seconds.

Last updated on July 29, 2026
Edit this page on GitHub