🚀 Pyversity Beginner Tutorial

Deploy Django on
Render

Connect GitHub → Render detects your project → your site goes live automatically. Modern, fast, and free to start!

7 Steps
~45 Minutes
Auto Deploys
How Render Deployment Works
💻 Your Code
(GitHub)
🗄️ Render
PostgreSQL DB
🌐 Render
Web Service
✅ Live at
.onrender.com
Your Progress
🎯
What is Render? Render is a modern cloud hosting platform. It connects directly to your GitHub repository — every time you push code, it automatically redeploys your website. It's like magic, but it's just technology! Render has a free tier perfect for student projects.
⚠️
Render's Free Tier Note: Free web services on Render will "spin down" after 15 minutes of inactivity — the first visit after that may take 30–60 seconds to load. This is normal for free tier. Free PostgreSQL databases expire after 90 days. Upgrade if you need a permanent project!
1
Step 1
Prepare Your Django Project
🛠️
Before we can deploy, we need to install a few extra packages and make some changes to your project. Render needs these to run Django properly.

Install these 4 packages in your local terminal:

bash — 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
PackageWhat it does
gunicornA web server that runs your Django app in production
dj-database-urlLets Django connect to Render's PostgreSQL database
psycopg2-binaryThe "driver" that talks between Python and PostgreSQL
whitenoiseServes your CSS, images, and JS files efficiently
2
Step 2
Update settings.py for Production
⚙️
We need to make your Django project "production ready" by updating its settings file. These changes make it secure and work on Render's servers.

Open your project's settings.py file and make these changes:

1. Add imports at the very top of settings.py:

python — settings.py (top of file)
import os
import dj_database_url

2. Update SECRET_KEY to use an environment variable:

python — settings.py
# 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):

python — settings.py
# 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:

python — settings.py
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):

python — settings.py
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:

python — settings.py
# 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 ) }
💡
Why all these changes? Locally you use SQLite (simple file database). Render uses PostgreSQL (powerful, real database). These settings let Django use SQLite when you're coding locally, and automatically switch to PostgreSQL when on Render.
3
Step 3
Create a build.sh Script
📜
Render needs a script that tells it what to do every time it deploys your project. We write this once and it runs automatically on every deploy!

Create a new file called build.sh in the root of your project (same folder as manage.py):

bash — build.sh (new file)
#!/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
📋
What does build.sh do? Every time you push code to GitHub, Render runs this script automatically. It installs your packages, copies CSS/images to the right place, and updates your database — like a robot helper that sets everything up for you!

Now commit everything to GitHub:

bash — your local terminal
git add . git commit -m "Add Render deployment config" git push
4
Step 4
Create a Free Render Account
🎉
Let's get you set up on Render — it's quick and free!
  • Go to render.com and click "Get Started for Free"
  • Sign up — the easiest way is using your GitHub account (click "Sign Up with GitHub")
  • Authorize Render to access your GitHub repositories
  • You'll land on the Render Dashboard — this is your mission control!
🔗
Sign up with GitHub! Using your GitHub account to sign up on Render makes it much easier to connect your repositories later. Highly recommended!
5
Step 5
Create a PostgreSQL Database on Render
🗄️
We need to create a real database for your project. Render gives you a free PostgreSQL database — much more powerful than SQLite!
  • On your Render dashboard, click the "New +" button (top right)
  • Select "PostgreSQL" from the dropdown
  • Give your database a name (e.g. myproject-db)
  • Leave all other settings as default
  • Select the Free tier and click "Create Database"
  • Wait for it to say "Available" (about 1–2 minutes)
  • Scroll down on the database page and find "Internal Database URL" — copy this value and save it somewhere!
Free databases expire in 90 days! This is fine for a school project or learning. If you want to keep it longer, you'll need to upgrade. Render will email you a reminder before it expires.
🔑
Internal vs External URL? Use the Internal Database URL — it's faster and more secure because both your web app and database are on Render's network. The External URL is for connecting from your laptop.
6
Step 6
Create a Web Service & Connect GitHub
🌐
Now we create the web service — this is what actually runs your Django project and serves it to the world!
  • Click "New +" again and select "Web Service"
  • Choose "Build and deploy from a Git repository" and click Next
  • Find your Django project repository and click "Connect"

Now fill in the settings form:

FieldWhat to enter
NameYour app name (e.g. my-django-app)
LanguagePython 3
Branchmain (or master)
Build Command./build.sh
Start Commandgunicorn yourprojectname.wsgi
Instance TypeFree
🔁 Replace: 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):

Environment Variables to Add
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
🔐
How do I make a SECRET_KEY? A SECRET_KEY should be a long, random string. You can generate one at djecrety.ir — just click the button and copy the result!
  • Click "Create Web Service" — Render will start building your project!
  • Watch the deploy logs scroll by (this takes 3–5 minutes on first deploy)
7
Step 7
Visit Your Live Website! 🚀
🎊
The moment of truth — let's check if your site is live!
  • Wait for the deploy log to show "Your service is live 🎉" or status changes to "Live"
  • Click the URL at the top of your web service page — it looks like your-app-name.onrender.com
  • 🎉 Your Django website is now live on the internet!
🐛
Something went wrong? Click on the "Logs" tab in your web service to see what happened. Common issues:

Build fails → check that build.sh is in the root folder and requirements.txt is correct
App crashes → check your Start Command — is yourprojectname correct?
Database errors → make sure DATABASE_URL environment variable is set correctly
Static files missing → check WhiteNoise is in MIDDLEWARE in settings.py
🔄
Auto-deploys are magical! From now on, any time you run git push from your laptop, Render will automatically detect the change and redeploy your site within a few minutes. No manual steps needed!
👤
Need to create a Django admin superuser? Go to your Render web service → click "Shell" tab → run:
python manage.py createsuperuser
FeatureRender Free Tier
Web servicesUnlimited (free spins down after inactivity)
PostgreSQL databases1 (expires after 90 days)
Auto-deploys from GitHub✅ Yes
Custom domainNot on free tier
HTTPS✅ Automatic
🚀

Legendary! You Deployed on Render!

Your Django website is now live at your-app-name.onrender.com

Every time you push code to GitHub, your site updates automatically. You're now deploying like a professional developer. That's seriously impressive — well done! 🎉