</>
Skip to content
Django lessons (37/43)

Django — Deployment

Production Settings

# settings.py
DEBUG = False
ALLOWED_HOSTS = ['yourdomain.com']

# Security
SECURE_BROWSER_XSS_FILTER = True
SECURE_CONTENT_TYPE_NOSNIFF = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
SECURE_SSL_REDIRECT = True

WSGI Server

# Install gunicorn
pip install gunicorn

# Run
gunicorn mysite.wsgi:application

Static Files

python manage.py collectstatic

Deployment Options

OptionDescription
HerokuPlatform as a Service
AWSEC2, Elastic Beanstalk
DigitalOceanVPS
PythonAnywherePython hosting
DockerContainerized

Heroku Deployment

# Procfile
web: gunicorn mysite.wsgi

# requirements.txt
pip freeze > requirements.txt

# Deploy
git push heroku main

Database

# PostgreSQL
pip install psycopg2
python manage.py migrate
python manage.py createsuperuser

Environment Variables

export DJANGO_SECRET_KEY='your-key'
export DJANGO_DEBUG='False'
export DATABASE_URL='postgres://...'

Mini Practice

  1. Configure production settings
  2. Set up gunicorn
  3. Deploy to Heroku
  4. Configure database

Up Next

Continue with REST Framework — building REST APIs.

Related Topics

Frequently Asked Questions about Deployment

What is Deployment in Django?

Deployment is a fundamental concept in Django. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Deployment?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Deployment.

Why is Deployment important in Django?

Deployment is essential for Django development. Understanding this concept will help you write better code and solve real-world problems more effectively.