Working with Django?

Django app nobody wants to touch? We pick it up.

Most of the Django we inherit was fine four or five releases ago, then nobody ran the upgrade and nobody wrote down how the admin ties into the models. We get it onto a supported LTS release, with migrations tidy and the admin usable, and leave it ready for the next pair of hands.

  • Since 2015Fixing technology
  • FreeEstimates
  • US teamReal engineers

django.log

still failing

What it is

Django at a glance

Django is a high-level Python web framework, first released in July 2005 by Adrian Holovaty and Simon Willison at the Lawrence Journal-World newspaper, and now maintained by the Django Software Foundation. The name is a nod to the guitarist Django Reinhardt.

The framework follows what its authors call a batteries-included philosophy: the ORM, migrations, admin site, authentication, template engine, forms layer and security middleware all ship together in the box. The current long-term support line is the Django 5 series, with LTS releases cut roughly every two years.

Django powers everything from content platforms like Wagtail and Mezzanine to very large production sites. Instagram was originally built on Django, and plenty of SaaS back ends, intranet tools and data-heavy admin apps still run on it today.

Type
Python web framework
First released
2005
License
BSD 3-Clause
Maintained by
Django Software Foundation
Typically used for
Content sites, SaaS back ends, admin apps, data-heavy web apps, APIs via DRF

The honest version

Django pros and cons

No technology is all upside. This is where Django earns its place and where it tends to cause trouble.

Where Django is strong

  • Batteries included from day oneAdmin interface, ORM, authentication, migrations, templates, forms and internationalisation all arrive in the same install, so there is no week spent picking a stack before writing a line of business logic.
  • The documentation is genuinely goodDjango's official docs are one of the better reference manuals in open source, which matters a great deal when somebody new has to pick up an unfamiliar codebase and get oriented quickly.
  • A mature, dependable ORMThe query API has been refined for twenty years and handles joins, aggregation, subqueries and raw SQL escape hatches without forcing you into any of them when they do not fit.
  • Django REST Framework for APIsDRF is the de facto way to expose Django models as a JSON API, with serializers, viewsets, auth and permissions that plug into everything Django already knows about the data.
  • Async support since Django 3.1Async views, middleware and ORM operations are available where they help, while synchronous code keeps working unchanged alongside them in the same project.
  • Strong security defaultsCSRF protection, XSS escaping in templates, SQL injection avoidance through the ORM, clickjacking headers and password hashing are all on out of the box rather than left as homework.
  • LTS releases every two yearsThe Django team publishes a long-term support release roughly every two years with three years of security fixes, which gives teams a predictable upgrade cadence to plan around.

Where Django bites

  • N+1 queries are easy to writeThe ORM makes it cheap to iterate over a queryset and touch a related field in the loop, and each of those touches is another round trip to the database unless select_related or prefetch_related is used.
  • Migrations drift when teams branchTwo developers on two branches both run makemigrations against the same model, and the resulting migration numbers collide at merge time unless somebody squashes or renumbers them carefully.
  • The admin is powerful but not a customer UIDjango admin is wonderful for staff and operations work, and consistently the wrong tool when somebody tries to hand it to end customers as the main interface of a product.
  • The forms framework feels datedServer-rendered forms with template widgets were state of the art in 2005 and now sit awkwardly next to the single-page frontends that most new user-facing features are built against.
  • Major upgrades mean deprecation sweepsMoving between major Django versions is rarely a one-line change. Each jump removes a few APIs that were flagged as deprecated two releases earlier, which legacy codebases tend to lean on.
  • Production footguns are still commonLeaving DEBUG = True on a live server and committing the SECRET_KEY to a public repository remain the two most common Django mistakes we see, and both are easy to make by accident.

Sound familiar?

Common Django problems we fix

The Django problems that bring people to us, and what you have once each one is fixed.

Django 2.2 · EOL April 2022

Stuck on a Django version that no longer gets security fixes

An app that was last upgraded when Django 2.2 was current, now running on a Python version the newer Django lines do not support either, and no plan to move forward.

On a current LTS, upgrade rehearsed

author: unknown

The developer who built it has left

A Django project with custom middleware, undocumented management commands and a tangle of signals, and nobody left who can explain what each piece is for.

Read, documented, maintainable

DisallowedHost: Invalid HTTP_HOST header

ALLOWED_HOSTS is wrong after a move

A site moved to a new domain or behind a new load balancer and the settings file was never updated, so the error log is a wall of DisallowedHost tracebacks.

Hosts and proxy headers configured correctly

duration: 9.4s · 142 queries

Pages that used to be snappy are slow

Classic N+1 behaviour in the ORM, usually a listing view that renders a related field for every row without prefetching it first.

Queries reduced, pages responsive

DEBUG = True

Debug mode left on in production

A yellow Django error page served to the public internet, leaking the settings file, installed apps and parts of the environment to anyone who can trigger an exception.

Debug off, errors logged privately

conflicting migrations

Migrations are a mess

Two branches each added a migration with the same number against the same app, or the migration history on disk does not match what the database thinks has been applied.

Migration tree reconciled, tests green

SECRET_KEY exposed

Secrets committed to version control

The SECRET_KEY, database password and third-party API keys all sitting in settings.py in the git history, visible to everyone who has ever had a clone of the repo.

Secrets rotated, moved out of the repo

What we do

Django help, from rescue to upkeep

Call us for one broken view, or hand us the whole project.

Version upgrades
Moving Django 2.2 and 3.x projects up to a current LTS release, one step at a time, with the test suite expanded along the way so regressions get caught before the next step.
Takeovers
Inheriting a Django codebase whose author is no longer available, reading it until we understand it, and leaving it documented well enough to hand on again.
Performance
Finding the slow views, the missing prefetches and the queries that scan the whole table, and fixing the handful that account for most of the pain.
APIs with DRF
Building and maintaining JSON APIs on Django REST Framework, including authentication, permissions, pagination and versioning where they matter.
Security tidy-up
Rotating leaked keys, turning debug mode off safely, configuring ALLOWED_HOSTS and CSRF properly, and making sure the deploy pipeline does not undo any of it.
Managed Tech
Dependency updates, security patches, monitoring and a team to call, so a Django app never quietly drifts into unsupported territory again.

How it works

From first message to fixed

  1. Look Free estimate

    Tell us what's going wrong. We look at it, then tell you plainly what's wrong and what it will cost.

  2. Fix

    We fix the cause, not the symptom. If something is down, getting it back up comes first.

  3. Harden

    Backups, monitoring, updates and access, so the same problem can't quietly come back.

  4. Hand back or stay on

    You get a plain-language write-up. Or we stay on for hosting, upkeep and new work.

Often found together

Running Django alongside something else?

We work on the whole stack, so the problem can be wherever it actually is.

Questions

Django questions

Something else? Call+1 737 727 7327

Can you upgrade our Django 2.2 or 3.x app to Django 5?

Yes, and this is a large share of our Django work. We move through the intermediate major versions one at a time rather than jumping, run the test suite against each step, fix the deprecations the release notes flag, and put the app into production on a current LTS release at the end. We expand the test coverage before the upgrade starts if it is thin, because upgrading without tests is guessing.

Can you take over a Django app from a developer who has left?

Yes. We read the codebase properly, including the settings, URL configuration, models, signals and any management commands, and write down how the pieces fit together. We get it running cleanly on a reproducible environment, rotate any credentials the previous developer had, and hand you something a new engineer can actually pick up.

Why does our Django site keep showing 'DisallowedHost' errors?

The ALLOWED_HOSTS setting does not include the hostname the request arrived with. This happens after a domain change, when a new load balancer or CDN is added in front, or when the site is accessed by IP. The fix is to put the real hostnames into ALLOWED_HOSTS and make sure any proxy in front is passing the Host header through correctly.

How do we speed up slow Django queries?

Almost always by eliminating N+1 patterns. A listing view touches a related field for each row, and the ORM issues one extra query per row unless select_related or prefetch_related is used. The second most common cause is a missing database index on a column the code filters by. We measure first with django-debug-toolbar or query logging, then fix the handful of places that account for the bulk of the time.

Should we build the API in Django REST Framework or FastAPI?

If the data already lives in Django models and the admin, forms and auth are being used, Django REST Framework is almost always the right answer because it builds on what is already there. FastAPI makes more sense for a brand-new API service with no existing Django code, especially when async throughput or a lightweight footprint matters more than reusing an existing ORM and admin.

How much does Django help cost?

Estimates are free. Describe the project and what is going wrong, and you get a price before any work starts.

Free estimate

Django app giving you trouble?

Tell us what you're running and what's going wrong. A person reads it and comes back with an estimate.

  • No charge to find out what it will take
  • If it's urgent, say so

Replies come from a person. By sending, you authorize us to email you back. No marketing.