How to Deploy Django with PostgreSQL Online
Deploying a Django application can be tricky due to static file collection, WSGI configurations, and migrating from SQLite to a production-grade database like PostgreSQL. This guide simplifies the process entirely.
Prepare Django for Production
Before leaving your local machine, ensure your `settings.py` is configured securely utilizing
dj-database-url.
import dj_database_url
import os
DATABASES = {
'default': dj_database_url.config(default=os.environ.get('DATABASE_URL'))
}
ALLOWED_HOSTS = ['*'] # Restrict this later to your specific domain
DEBUG = False # Ensure this is False in production
Serving Static Files
Django doesn't natively serve static files (like CSS, images) in production securely. You should use `WhiteNoise`.
pip install whitenoise
pip freeze > requirements.txt
Add Gunicorn
Django’s built-in server is only for development. Install `gunicorn` to deploy a multi-threaded application server.
Deploying using a Platform
Instead of manually provisioning Linux servers, simply link your GitHub repo to a modern PaaS like Remoud.
- Select your repository containing the `requirements.txt`.
- Set the start command to `gunicorn your_project.wsgi:application`.
- In the Environmental Variables section, define your `DATABASE_URL` pointing to your hosted PostgreSQL database (like Supabase or an AWS RDS instance).
- Deploy!
Deploy Python Intelligently
Skip the EC2 manuals. Deploy Django faster and easier with Remoud's Git-driven pipeline.
Start deploying for free →