Deploying your Django app to Render.com is fast and easy if you follow the right steps. In this blog, I’ll walk you through setting up a production-ready Django project on Render, including database configuration, static files, and more.


🧱 1. Prepare Your Django Project

Start with a Django project that runs locally.

✅ Install Required Packages

Make sure you have the following in requirements.txt:

gunicorn
dj-database-url
psycopg2-binary
whitenoise

Install them if needed:

pip install gunicorn dj-database-url psycopg2-binary whitenoise

⚙️ 2. Update Django Settings for Production

Edit your settings.py:

🔐 Allowed Hosts

ALLOWED_HOSTS = ['your-app-name.onrender.com']

🧾 Use this .env file (You can add your other variables)

You can use a library like django-environ to access your variables in settings.py.

DEBUG=0
SECRET_KEY=your-complex-secret-key
ALLOWED_HOSTS=localhost,127.0.0.1,your-app-name.onrender.com
DATABASE_URL=postgres://db_user:password@hostname:PORT/db_name

🗄️ Database (PostgreSQL)

Replace the default SQLite config:

import dj_database_url
import os

DATABASES = {
    'default': dj_database_url.config(
        default=os.environ.get('DATABASE_URL'),
        conn_max_age=600,
        ssl_require=True
    )
}

Render will inject the DATABASE_URL environment variable when you connect your PostgreSQL service.

🧾 Static Files

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

MIDDLEWARE = [
    'whitenoise.middleware.WhiteNoiseMiddleware',
    # ... existing middleware
]

📦 3. Add a Procfile in the Root Directory

Render uses this to know how to run your app:

web: gunicorn your_project_name.wsgi

Replace your_project_name with your actual Django project folder name.


🗃️ 4. Set Up a PostgreSQL Database on Render

  1. Go to Render dashboard → Databases → New PostgreSQL
  2. Copy the generated DATABASE_URL
  3. Go to your Web Service → Environment → Add:
    • DATABASE_URL =
  4. Or you can directly upload your .env file

⚙️ 5. Set Up Static Files and Migrations

Option A: Use render.yaml

Create a render.yaml file:

services:
  - type: web
    name: your-app-name
    env: python
    buildCommand: |
      pip install -r requirements.txt
      python manage.py collectstatic --noinput
      python manage.py migrate
    startCommand: gunicorn your_project_name.wsgi
    envVars:
      - key: DJANGO_SETTINGS_MODULE
        value: your_project_name.settings

Push this to your GitHub repo.

Option B: Manually Run Migrations and Collectstatic

Use the Shell in Render’s dashboard:

python manage.py migrate
python manage.py collectstatic --noinput

✅ 6. Final Touches

  • Make sure DEBUG = False in production.
  • Use SECRET_KEY from an environment variable.
  • If you use media files (uploads), you’ll need S3 or similar.

🏁 You're Live!

After all these steps, your Django app should be live at:

https://your-app-name.onrender.com/

If the admin panel has no styles — don’t worry, just ensure:

python manage.py collectstatic --noinput

...and it’ll work like a charm 🚀


💬 Feel free to drop a comment if you face any issues — happy to help!