Overview

Django 1.3, released on March 23, 2011, introduces Class-Based Views, a major shift in how Django views are structured. This release also adds static file handling support and logging via Python's logging module.

Key Features

Class-Based Views

Class-Based Views allow reusing and composing view logic through inheritance. Django provides generic views for common operations: lists, details, creation, updates, and deletion.

python
from django.views.generic import ListView, DetailView

class ArticleList(ListView):
    model = Article
    template_name = 'blog/list.html'
    context_object_name = 'articles'
    paginate_by = 10

    def get_queryset(self):
        return Article.objects.filter(published=True)

class ArticleDetail(DetailView):
    model = Article
    template_name = 'blog/detail.html'
    context_object_name = 'article'

    def get_queryset(self):
        return Article.objects.filter(published=True)

# urls.py
# url(r'^articles/$', ArticleList.as_view()),
# url(r'^articles/(?P<pk>\d+)/$', ArticleDetail.as_view()),

Static files management

The staticfiles framework centralizes the management of CSS, JavaScript, and image files. The collectstatic command gathers all static files for production deployment.

python
# settings.py
STATIC_URL = '/static/'
STATIC_ROOT = '/var/www/static/'

INSTALLED_APPS = [
    'django.contrib.staticfiles',
    # ...
]

# In the HTML template:
# {% load static %}
# <link rel="stylesheet" href="{% static 'css/style.css' %}">
# <script src="{% static 'js/app.js' %}"></script>

# Deployment: collect all static files
# python manage.py collectstatic

Sources