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!

Python-ready auth and billing that just works

Python-ready auth and billing that just works

Stop building auth from scratch. Kinde handles authentication, user management, and billing so you can focus on what matters - shipping great products your users will love.

Get a free account

Top comments (0)

Your Python stack deserves better infra

Your Python stack deserves better infra

Stop duct-taping user flows together. Manage auth, access, and billing in one simple SDK with Kinde.

Get a free account

๐Ÿ‘‹ Kindness is contagious

Dive into this thoughtful piece, beloved in the supportive DEV Community. Coders of every background are invited to share and elevate our collective know-how.

A sincere "thank you" can brighten someone's dayโ€”leave your appreciation below!

On DEV, sharing knowledge smooths our journey and tightens our community bonds. Enjoyed this? A quick thank you to the author is hugely appreciated.

Okay