DEV Community

Ravi Shanker Kushwaha
Ravi Shanker Kushwaha

Posted on

πŸš€ How to Deploy a Django App on Render.com β€” Step-by-Step Guide

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
Enter fullscreen mode Exit fullscreen mode

Install them if needed:

pip install gunicorn dj-database-url psycopg2-binary whitenoise
Enter fullscreen mode Exit fullscreen mode

βš™οΈ 2. Update Django Settings for Production

Edit your settings.py:

πŸ” Allowed Hosts

ALLOWED_HOSTS = ['your-app-name.onrender.com']
Enter fullscreen mode Exit fullscreen mode

🧾 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
Enter fullscreen mode Exit fullscreen mode

πŸ—„οΈ 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
    )
}
Enter fullscreen mode Exit fullscreen mode

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
]
Enter fullscreen mode Exit fullscreen mode

πŸ“¦ 3. Add a Procfile in the Root Directory

Render uses this to know how to run your app:

web: gunicorn your_project_name.wsgi
Enter fullscreen mode Exit fullscreen mode

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 = <paste_here>
  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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

βœ… 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/
Enter fullscreen mode Exit fullscreen mode

If the admin panel has no styles β€” don’t worry, just ensure:

python manage.py collectstatic --noinput
Enter fullscreen mode Exit fullscreen mode

...and it’ll work like a charm πŸš€


πŸ’¬ Feel free to drop a comment if you face any issues β€” happy to help!

Heroku

Deliver your unique apps, your own way.

Heroku tackles the toil β€” patching and upgrading, 24/7 ops and security, build systems, failovers, and more. Stay focused on building great data-driven applications.

Learn More

Top comments (0)