πŸš€ Day 10: Django Deployment – Beginner’s Web Dev Series

Welcome to the final day (Day 10) of your Django web development journey!

Today, we’ll make your project publicly accessible on the internet by deploying it to Render.com, a free and beginner-friendly platform for hosting Django apps.


πŸ“ What You’ll Learn

  1. Preparing your Django app for production

  2. Creating requirements.txt with Gunicorn

  3. Setting up environment variables with python-decouple

  4. Using collectstatic for static file handling

  5. Connecting your GitHub repo to Render


πŸ”§ 1. Prepare Your Project for Deployment

Install Gunicorn for production-ready server handling:

pip install gunicorn

Then freeze dependencies:

pip freeze > requirements.txt

πŸ› οΈ 2. Use python-decouple for Environment Variables

Install it:

pip install python-decouple

Update settings.py:

from decouple import config

SECRET_KEY = config("SECRET_KEY")
DEBUG = config("DEBUG", cast=bool, default=False)
ALLOWED_HOSTS = ["*"]

Create .env :

SECRET_KEY=your-secret
DEBUG=False

And also create .env.example:

DEBUG=False
SECRET_KEY=changeme

βš™οΈ 3. Update settings.py, urls.py for Static, Media Files

# settings.py
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')

# urls.py
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

πŸ“ 4. Add .gitignore

*.pyc
__pycache__/
.env
staticfiles/
db.sqlite3

πŸ”ƒ 5. Add collectstatic to Your Flow

Make sure this is ready in your production setup:

python manage.py collectstatic

This command copies all static files to STATIC_ROOT, so they can be served in production.


πŸ› οΈ 6. Push to GitHub

git init
git add .
git commit -m "Prepare for Render deployment"
git remote add origin https://github.com/yourusername/yourproject.git
git push -u origin main

🌐 7. Deploy on Render

  1. Visit https://render.com

  2. Create a free account

  3. Click New Web Service

  4. Connect your GitHub repo

  5. Select the repo

  6. Wait for it to build and deploy (~3–5 mins)


βœ… Task for Day 10

  • Create a .env, .env.example, and requirements.txt

  • Add Gunicorn to the project

  • Push your code to GitHub

  • Deploy to Render

  • Share your live link with your team/community!


🏁 You Did It!

πŸŽ‰ Congratulations on completing the 10-Day Django Beginner Series!

You now know how to:

  • Build dynamic views and templates

  • Work with models and forms

  • Handle authentication

  • Build RESTful APIs

  • And deploy your Django app to the web

πŸ§‘β€πŸ’» Beginner Resources

1. Official Django Documentation

2. MDN Django Tutorial (by Mozilla)

3. Real Python Django Series

4. Django for Beginners Book (by William S. Vincent)


0
Subscribe to my newsletter

Read articles from Shankar Lamichhane directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Shankar Lamichhane
Shankar Lamichhane

Hi, I’m Shankar β€” a Sr. Software Engineer specializing in Python, Django, and DevOps. I build scalable web applications, APIs, and cloud-native systems, with a focus on clean architecture and backend automation.