PYTHON APPLIEDChapter 12 · Python for Web Development
Django: the batteries-included framework
Django is a full-featured Python web framework that follows the Model-View-Template pattern. It comes with a built-in ORM for database queries, an admin panel, authentication, and URL routing out of the box.
Worked example
# models.py - define your data shape
from django.db import models
class Star(models.Model):
name = models.CharField(max_length=100)
magnitude = models.FloatField()
def __str__(self):
return self.name
# views.py - handle HTTP requests
from django.http import JsonResponse
from .models import Star
def star_list(request):
stars = list(Star.objects.values("name", "magnitude"))
return JsonResponse(stars, safe=False)How it reads
- models.Model turns a Python class into a database table via the ORM
- Star.objects.values(...) queries the database and returns matching rows
- JsonResponse sends data back to the client as JSON

Cloud tip: Django's ORM lets you query the database using Python instead of writing raw SQL. Migrations keep your database schema in sync with your models.


