Skip to content

Chapter 1: First Look at Django

1.1 Hello, Django!

Web Framework Concept

A web framework is a software framework for developing web applications. It provides a set of tools and libraries to simplify the web development process. Web frameworks usually include these core functions:

  • URL routing: Map URL requests to corresponding handler functions
  • Template system: Generate HTML pages dynamically
  • Database abstraction layer: Simplify database operations
  • Form handling: Process user input and data validation
  • Session management: Manage user state and authentication

Django Introduction

Django is pronounced /ˈdʒæŋɡoʊ/. It is a Python web framework started by Adrian Holovaty and Simon Willison in 2003, first released in 2005. The latest version is 5.2 (as of September 2025).

Django Core Features

  1. Fast development: Django provides many built-in features, allowing developers to build web apps quickly
  2. Security: Built-in security mechanisms like CSRF protection, SQL injection prevention
  3. Scalability: Supports development and deployment of large applications
  4. Complete functionality: Includes ORM, admin interface, authentication system
  5. Good documentation: Has detailed official documentation and active community

Django Design Philosophy

DRY (Don't Repeat Yourself)

Django follows DRY principle to avoid code repetition. For example:

  • Define models once, automatically generate database tables and admin interface
  • Centralized URL configuration, avoid hardcoding
  • Template inheritance reduces repeated HTML code

Simply put, develop based on framework standards. Django provides tools to complete necessary functions, developers focus on business logic.

python
# Model definition example
class Article(models.Model):
    title = models.CharField(max_length=200)
    content = models.TextField()
    created_at = models.DateTimeField(auto_now_add=True)
    
    def __str__(self):
        return self.title

Fast Development

Django provides many out-of-the-box features:

bash
# Create project with one command
django-admin startproject myblog

# Create app with one command
python manage.py startapp blog

# Create admin interface with one command
python manage.py createsuperuser

Explicit Over Implicit

Django's configuration and code structure are clear, no "magic" behavior:

python
# URL configuration explicitly specifies paths and views
urlpatterns = [
    path('articles/', views.article_list, name='article_list'),
    path('articles/<int:id>/', views.article_detail, name='article_detail'),
]

Django vs Other Frameworks

Flask, FastAPI etc. are based on API development approach. They can quickly build prototype systems, running API services with one file. But for complex scenarios like authentication, permission control, middleware, many plugins are needed. In the end, they become similar to Django.

Django vs Flask

FeatureDjangoFlask
Learning curveSteeper, feature-richGentle, simple lightweight
Built-in featuresComplete (ORM, Admin, auth)Minimal core, needs extensions
Project structureConvention over configurationFlexible customization
Use casesMedium to large projectsSmall projects, API services
python
# Django view example
from django.shortcuts import render
from .models import Article

def article_list(request):
    articles = Article.objects.all()
    return render(request, 'blog/article_list.html', {'articles': articles})
python
# Flask view example
from flask import Flask, render_template

app = Flask(__name__)

@app.route('/articles')
def article_list():
    # Need to handle database connection and queries manually
    articles = get_articles_from_db()
    return render_template('article_list.html', articles=articles)

Django vs FastAPI

FeatureDjangoFastAPI
Main purposeFull-stack web developmentAPI development
PerformanceMediumHigh performance
Type hintsPartial supportNative support
Async supportDjango 3.1+Native async

Django Use Cases

Project Types Suitable for Django

  1. Content Management Systems (CMS)

    • News websites
    • Blog platforms
    • Company websites
  2. E-commerce Platforms

    • Online stores
    • Marketplace platforms
    • Order management systems
  3. Social Network Applications

    • Forum systems
    • Social media platforms
    • Online communities
  4. Enterprise Application Systems

    • Customer Relationship Management (CRM)
    • Enterprise Resource Planning (ERP)
    • Project management systems

Well-known Websites Using Django

  • Instagram: World's largest image sharing platform
  • Pinterest: Image collection and sharing website
  • Mozilla: Firefox browser official website
  • Washington Post: Washington Post official website
  • Bitbucket: Code hosting platform

Summary

Django as a complete Python web framework has clear advantages:

  1. ✅ Uses "batteries included" design philosophy, rich built-in features
  2. ✅ Follows DRY principle, avoids code repetition
  3. ✅ Provides fast development capability, improves development efficiency
  4. ✅ Has complete security mechanisms and active community support
  5. ✅ Suitable for various types of web project development

Understanding Django basic concepts is the first step in learning Django development.

Next Article

We will set up Django development environment.

1.2 Django Environment Setup →

Directory

Return to Course Directory

Released under the [BY-NC-ND License](https://creativecommons.org/licenses/by-nc-nd/4.0/deed.en).