Skip to content

Quickstart: Deploy a Django App

This guide explains how to deploy a Django application to Seenode. For a production-ready setup, we recommend using a PostgreSQL database and WhiteNoise to serve static files.

Get started in seconds by deploying our pre-configured Django template. This example is ready to deploy and reflects the structure discussed in this guide.

Follow these steps to prepare and deploy your Django project.

  1. Prepare Your Project for Production

    Project Structure

    Your Django project should have the following basic structure:

    • Directoryyour-django-project/
      • manage.py
      • requirements.txt
      • build.sh
      • Directoryyour_project/
        • settings.py
        • urls.py
        • wsgi.py
        • asgi.py

    Install Recommended Packages

    For a production setup, we recommend adding gunicorn, dj-database-url, and whitenoise to your requirements.txt:

    requirements.txt
    gunicorn
    dj-database-url
    psycopg2-binary # Or the appropriate adapter for your database
    whitenoise

    Update settings.py

    • Database: Configure your DATABASES setting to use the DATABASE_URL environment variable that Seenode provides.
    • Static Files: Set up WhiteNoise to serve your static files. When you run your app in production with DEBUG=False, Django’s development server no longer serves static assets. WhiteNoise provides a simple way for your Gunicorn server to handle these files.
    • Security: It is best practice to load your SECRET_KEY from an environment variable and set DEBUG=False in production.
    your_project/settings.py
    import os
    import dj_database_url
    # ...
    SECRET_KEY = os.environ.get('SECRET_KEY')
    DEBUG = os.environ.get('DEBUG', 'False').lower() == 'true'
    ALLOWED_HOSTS = os.environ.get('ALLOWED_HOSTS', '').split(',')
    # ...
    DATABASES = {
    'default': dj_database_url.config(conn_max_age=600, ssl_require=True)
    }
    # ...
    MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware', # Add WhiteNoise
    # ...
    ]
    STATIC_URL = '/static/'
    STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
    STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
  2. Create a Build Script (Optional)

    To streamline deployments, you can create a build.sh script to run migrations and collect static files automatically.

    build.sh
    #!/usr/bin/env bash
    # exit on error
    set -o errexit
    pip install -r requirements.txt
    python manage.py collectstatic --no-input
    python manage.py migrate

    Make the script executable: chmod +x build.sh

  3. Deploy on Seenode

    Follow these steps to deploy your Django application:

    1. First, create a PostgreSQL Database from the Seenode Dashboard if your application needs one. Seenode also supports MySQL.
    2. Create a new Web Service and connect your Django project’s Git repository. Configure your build and start commands in the settings. A common setup is:
      • Build Command: ./build.sh
      • Start Command: gunicorn your_project.wsgi --bind 0.0.0.0:8000
    3. Navigate to the Environment tab and link your PostgreSQL database. Seenode will automatically configure the DATABASE_URL.
    4. Configure your production environment variables, including SECRET_KEY and ALLOWED_HOSTS.
    5. Choose your preferred instance size and create your service.
    6. Watch your deployment progress in real-time through the Logs tab.
    7. Once complete, your Django application will be accessible via your service’s URL.

Now that your Django application is deployed, here are some things you might want to do next: