Think Build Implement Repeat
London, UK +44 7367 067226
WhatsApp FOLLOW f in X
  1. Home
  2. Blog
  3. The Django Patterns We See Most
Python & Django

The Django Patterns We See Most

Common Django application mistakes, from query multiplication and missing record-level permissions to debug left on, and how to fix each without a rewrite.

Updated 2 min readBy SpiderHunts Technologies

Free estimateNo obligation

Get a free estimate

Tell us what you need. A senior engineer reads every enquiry.

Takes under a minute. We never share your details.

  • Free consultation
  • No commitment
  • NDA on request

Prefer to talk? Book a free 30-minute call →

Quick answer — TL;DR

Query multiplication, missing record-level permissions, debug on in production, email through the default backend, and no tests around the business rules.

The five most common

  1. Query multiplication — lazy loading in loops
  2. Record-level permissions missing — action checked, ownership not
  3. Debug left on in production
  4. Email through the default backend, silently not arriving
  5. No tests around the business rules and permissions
The second is the most serious. A user permitted to view orders viewing someone else's order is a data breach, and it is depressingly common.

Five more

  • Business logic in views, so it cannot be reused or tested
  • Fat models with everything in save methods, so ordering matters and nothing is clear
  • Secrets in settings committed to the repository
  • Media served from the code directory
  • Migrations edited after being applied somewhere

Costs

MistakeTypical cost
Query multiplicationPages that take ten seconds
Missing record permissionsA data breach
Debug in productionFull exposure of settings and queries
Default email backendMonths of lost enquiries
No testsChanges take three times as long

All fixable without a rewrite

Every one of these is addressable incrementally in an existing application. None requires replacement, which is worth knowing before anyone proposes one.

Fix the permissions and the production settings first — those are the ones with the most serious consequences.

How to find them

  1. Run Django's deployment check — seconds, catches configuration
  2. Log query counts per page — finds multiplication immediately
  3. Try to access another user's record — finds permission gaps
  4. Send yourself an email from production — checks delivery
  5. Look for tests around the calculations — usually absent

FAQ

Frequently asked questions

The questions readers ask us after this guide.

Still have a question?

Ask us directly — a senior engineer will get back to you.

Ask about your project

Which should we fix first?

Record-level permissions and production settings. Those have the most serious consequences.

How do we find query multiplication?

Log the count per request. Any page issuing more than a few dozen is worth investigating.

Can these be fixed incrementally?

All of them. None requires a rewrite.

How do we prevent them recurring?

Tests, the deployment check in the pipeline, and query count assertions on list views.

Keep reading

More on Python & Django

Python & Django

An API Other Systems Can Depend On

Designing a Python API service others can depend on: validation at the boundary, consistent errors and status codes, early versioning and documentation.

Python & Django

Moving and Transforming Data Reliably

Building data pipelines in Python that cope with malformed input: restartable stages, quarantining failures, reconciling counts and alerting on absence.

Start here

Recognise more than three of these?

Most inherited applications have them. Permissions first — that is where the exposure is.

  1. You tell us what you needTwo minutes on the form, or a message on WhatsApp.
  2. A senior engineer reviews itAnd comes back with questions, a realistic range and an honest view on fit.
  3. Free 30-minute scoping callWe talk through scope, options and a realistic estimate — with no obligation.
Free estimateNo obligation

Talk to someone who builds this

Send a short brief and we will come back with an honest view and a realistic range.

Takes under a minute. We never share your details.

  • Free consultation
  • No commitment
  • NDA on request

Prefer to talk? Book a free 30-minute call →