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.
Deploy a Django Template
Section titled “Deploy a Django Template”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.
Django Template
Deploy a Django project pre-configured with Gunicorn for production.Deploying an Existing Django Project
Section titled “Deploying an Existing Django Project”Follow these steps to prepare and deploy your Django project.
-
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
, andwhitenoise
to yourrequirements.txt
:requirements.txt gunicorndj-database-urlpsycopg2-binary # Or the appropriate adapter for your databasewhitenoiseUpdate
settings.py
- Database: Configure your
DATABASES
setting to use theDATABASE_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 setDEBUG=False
in production.
your_project/settings.py import osimport 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' -
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 errorset -o errexitpip install -r requirements.txtpython manage.py collectstatic --no-inputpython manage.py migrateMake the script executable:
chmod +x build.sh
-
Deploy on Seenode
Follow these steps to deploy your Django application:
- First, create a PostgreSQL Database from the Seenode Dashboard if your application needs one. Seenode also supports MySQL.
- 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
- Build Command:
- Navigate to the Environment tab and link your PostgreSQL database. Seenode will automatically configure the
DATABASE_URL
. - Configure your production environment variables, including
SECRET_KEY
andALLOWED_HOSTS
. - Choose your preferred instance size and create your service.
- Watch your deployment progress in real-time through the Logs tab.
- Once complete, your Django application will be accessible via your service’s URL.
Next Steps
Section titled “Next Steps”Now that your Django application is deployed, here are some things you might want to do next:
Set up a Custom Domain (Coming Soon)
Configure a custom domain to point to your new web service.Connect to a Database
Instantly scaffold and connect PostgreSQL and MySQL databases