Connect GitHub → Render detects your project → your site goes live automatically. Modern, fast, and free to start!
Install these 4 packages in your local terminal:
# These packages help Render serve your Django app pip install gunicorn dj-database-url psycopg2-binary whitenoise # Save all your packages to requirements.txt pip freeze > requirements.txt
| Package | What it does |
|---|---|
gunicorn | A web server that runs your Django app in production |
dj-database-url | Lets Django connect to Render's PostgreSQL database |
psycopg2-binary | The "driver" that talks between Python and PostgreSQL |
whitenoise | Serves your CSS, images, and JS files efficiently |
Open your project's settings.py file and make these changes:
1. Add imports at the very top of settings.py:
import os import dj_database_url
2. Update SECRET_KEY to use an environment variable:
# Replace your existing SECRET_KEY line with this: SECRET_KEY = os.environ.get('SECRET_KEY', 'your-fallback-dev-key')
3. Set DEBUG smartly (off in production, on in development):
# Render sets an environment variable called 'RENDER' # We use that to detect if we're on Render or your local machine DEBUG = 'RENDER' not in os.environ
4. Update ALLOWED_HOSTS:
ALLOWED_HOSTS = [] # Render gives us the hostname automatically — we grab it here RENDER_EXTERNAL_HOSTNAME = os.environ.get('RENDER_EXTERNAL_HOSTNAME') if RENDER_EXTERNAL_HOSTNAME: ALLOWED_HOSTS.append(RENDER_EXTERNAL_HOSTNAME)
5. Add WhiteNoise to MIDDLEWARE (for static files like CSS):
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware', # ← Add this line!
# ... rest of your middleware stays the same
]
# Also add this line anywhere in settings.py:
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
6. Update the DATABASES setting to use Render's PostgreSQL:
# Replace your existing DATABASES block with this: DATABASES = { 'default': dj_database_url.config( default='sqlite:///db.sqlite3', # fallback for local dev conn_max_age=600 ) }
Create a new file called build.sh in the root of your project (same folder as manage.py):
#!/usr/bin/env bash # Exit immediately if anything fails set -o errexit # Install all Python packages pip install -r requirements.txt # Collect all static files (CSS, JS, images) python manage.py collectstatic --no-input # Apply any database changes (migrations) python manage.py migrate
Now commit everything to GitHub:
git add . git commit -m "Add Render deployment config" git push
myproject-db)
Now fill in the settings form:
| Field | What to enter |
|---|---|
| Name | Your app name (e.g. my-django-app) |
| Language | Python 3 |
| Branch | main (or master) |
| Build Command | ./build.sh |
| Start Command | gunicorn yourprojectname.wsgi |
| Instance Type | Free |
yourprojectname in the Start Command with the name of the folder that contains your wsgi.py file (same folder as settings.py).
Add these Environment Variables (scroll down to find the section):
Key: DATABASE_URL Value: (paste the Internal Database URL from Step 5) Key: SECRET_KEY Value: (create a long random string, e.g. use: openssl rand -base64 32) Key: PYTHON_VERSION Value: 3.10.0
your-app-name.onrender.com
build.sh is in the root folder and requirements.txt is correctyourprojectname correct?DATABASE_URL environment variable is set correctlygit push from your laptop, Render will automatically detect the change and redeploy your site within a few minutes. No manual steps needed!
python manage.py createsuperuser
| Feature | Render Free Tier |
|---|---|
| Web services | Unlimited (free spins down after inactivity) |
| PostgreSQL databases | 1 (expires after 90 days) |
| Auto-deploys from GitHub | ✅ Yes |
| Custom domain | Not on free tier |
| HTTPS | ✅ Automatic |