Getting Started

Django Introduction

Learn Django — the Python web framework for perfectionists with deadlines.

What is Django?

Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design. It follows the "batteries included" philosophy — it comes with everything you need: ORM, authentication, admin interface, form handling, and more.

> "The web framework for perfectionists with deadlines"

Django's Philosophy

  • DRY (Don't Repeat Yourself): Reuse code everywhere
  • Convention over configuration: Sensible defaults
  • Loose coupling: Components are independent
  • Explicit is better than implicit: Python's Zen

The MTV Pattern

Django uses Model-Template-View (MTV), similar to MVC:

  • Model: Data layer (ORM)
  • Template: Presentation layer (HTML)
  • View: Business logic (processes requests)

Getting Started

bash
pip install django
django-admin startproject myproject
cd myproject
python manage.py runserver

Example

python
# Create a new project
# django-admin startproject myproject

# Create an app within the project
# python manage.py startapp blog

# myproject/settings.py
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'blog',  # Our new app
]

# Run development server
# python manage.py runserver

# Create database migrations
# python manage.py makemigrations
# python manage.py migrate

# Create superuser
# python manage.py createsuperuser
Try it yourself — PYTHON