Skip to content

Why Django?

Django is a Python web framework with roots at the Lawrence Journal-World, a newspaper in Lawrence, Kansas. Its goal was to make web development easier and more efficient.

Non-technical editors also needed an easy way to change the content published on the web. Django was created so a small team of devs could build and maintain sophisticated, database-backed websites under publishing deadlines.

Django comes with a lot of what a site needs baked-in: an ORM, database migrations, an admin, forms, templates, sessions, user accounts, and more.

Who Uses Django

Instagram launched on Django in 2010. In 2016, its engineers described their site as the world's largest deployment of the Django web framework.

Most Django projects are much smaller. It's a common choice for content sites, internal tools, and the backends for iOS and Android apps and JavaScript frontends.

A Well Established Framework

Django's first release was in 2005, so it's currently a mature project at 21 years old.

Django offers:

  • Stability: Deprecations are announced well in advance. A deprecated API keeps working, with a warning, across two or more feature releases before being removed.
  • Security defaults: By default, queries are parameterized, templates autoescape variables, and the CSRF middleware rejects a form POST without a valid token.
  • Supported releases: Every release gets security fixes for a set length of time. For Django 6.1 (the version we use in class) support lasts until December 2027.

Pitfalls

  • Async: Views can be async, and most of the ORM has async methods. Transactions don't work with async queries yet.
  • APIs: Django wasn't originally designed for building APIs. Most projects add Django REST Framework or Django Ninja.
  • Frontend: Django renders pages on the server and serves static files, but it doesn't build JavaScript. A frontend written with React, Vue, or TypeScript needs its own build tools, such as Vite, and usually talks to Django through an API.

When to Pick FastAPI Versus Django

FastAPI

Lean towards FastAPI if your priority is:

  • Building mostly APIs
  • Python type hints and Pydantic validation
  • Automatic OpenAPI documentation
  • Async-first development

Django

Lean towards Django if your priority is:

  • Getting a complex, database-backed app with business logic into production
  • Learning one framework with a lot built-in
  • An admin interface