Python Web Framework
Django is a high-level Python web framework that follows the "batteries-included" philosophy, providing developers with a comprehensive set of tools for rapid web application development. Created in 2003 and released publicly in 2005, Django was designed to help developers build complex, database-driven websites quickly and with less code.
Named after jazz guitarist Django Reinhardt, the framework emphasizes reusability, the don't-repeat-yourself (DRY) principle, and automatic admin interfaces. Django follows the Model-View-Template (MVT) architectural pattern, a variation of the traditional Model-View-Controller (MVC) pattern.
# models.py from django.db import models from django.utils import timezone from django.contrib.auth.models import User class Category(models.Model): name = models.CharField(max_length=100) slug = models.SlugField(unique=True) def __str__(self): return self.name class Meta: verbose_name_plural = "Categories" class Article(models.Model): title = models.CharField(max_length=200) slug = models.SlugField(unique=True) content = models.TextField() category = models.ForeignKey(Category, on_delete=models.CASCADE) author = models.ForeignKey(User, on_delete=models.CASCADE) published_date = models.DateTimeField(default=timezone.now) is_featured = models.BooleanField(default=False) def __str__(self): return self.title
# views.py from django.shortcuts import render, get_object_or_404 from django.views.generic import ListView, DetailView from .models import Article, Category # Function-based view def article_detail(request, slug): article = get_object_or_404(Article, slug=slug) return render(request, 'blog/article_detail.html', { 'article': article, }) # Class-based view class ArticleListView(ListView): model = Article template_name = 'blog/article_list.html' context_object_name = 'articles' paginate_by = 10 def get_queryset(self): return Article.objects.filter( is_featured=True ).order_by('-published_date')
# urls.py from django.urls import path from . import views app_name = 'blog' urlpatterns = [ path('', views.ArticleListView.as_view(), name='article_list'), path('article/<slug:slug>/', views.article_detail, name='article_detail'), path('category/<slug:slug>/', views.CategoryDetailView.as_view(), name='category_detail'), ]
<!-- article_detail.html --> {% extends "base.html" %} {% block title %}{{ article.title }}{% endblock %} {% block content %} <article> <header> <h1>{{ article.title }}</h1> <div class="meta"> Published on {{ article.published_date|date:"F j, Y" }} by {{ article.author.username }} in <a href="{% url 'blog:category_detail' article.category.slug %}"> {{ article.category.name }} </a> </div> </header> <div class="content"> {{ article.content|safe }} </div> </article> {% endblock %}
Django is primarily used for:
Major milestones in Django's development:
Django follows a predictable release schedule with Long-Term Support (LTS) versions every two years, making it reliable for production systems.
Here are some excellent resources for learning Django:
Technologies often used with Django or alternative options: