Learning to Build Websites with Django
A developer explores building a backend-heavy website using Django instead of heavy frontend code. They share what works well, what is frustrating, and how fixing a template setting improved site performance.
In short: A developer explores building a backend-heavy website using Django instead of heavy frontend code. They share what works well, what is frustrating, and how fixing a template setting improved site performance.
Building websites can be done in many different ways, and choosing the right tools often involves a lot of trial and error.
What happened, in plain words
A developer who usually builds frontends or uses Go tried using Django to build a website with an SQL database and backend HTML rendering. They found that Django's query sets, template filters, and automatic database migrations made building much easier. However, they disliked using class-based view inheritance, dealt with automated scrapers sending traffic, and discovered that an accidental setting change was slowing down their site's template rendering.
Key points
- Custom query sets: The developer liked defining query sets with specific filters to make the view code easier to read.
- Template tools: Django templates offer useful built-in filters to handle dates, turn text links into clickable items, and manage query strings easily.
- Automatic migrations: Editing models to add new fields lets Django automatically generate migrations, helping the database adapt as understanding of the problem changes.
- View inheritance issues: Using class-based views and inheritance to share code between views was not enjoyable, leading the developer to switch to functions instead.
- Performance discoveries: An accidental turning-off of the cached template loader caused slowdowns, and fixing it helped the site handle more requests per second.
Terms explained
- Django — A software framework that provides built-in tools to help build websites using a backend language. Example: A pre-built kitchen set that gives you the counters and sink so you do not have to build them from scratch.
- SQL database — A system used to store and organize information in tables. Example: A massive digital filing cabinet where you can quickly look up specific folders and files.
- Migrations — A way to safely update the structure of a database as a project changes over time. Example: Adding a new column to an existing spreadsheet without losing any of the old data inside it.
- Template caching — Saving the finished look of a webpage so the computer does not have to rebuild it from scratch every single time someone visits. Example: Keeping a photocopied drawing ready to hand out instead of redrawing it by hand for every person who asks.
Why it matters
Understanding how different web frameworks handle tasks and performance can help developers choose the right tools for their own projects.
What we still don't know
The source only reflects one person's personal experience and opinions while learning Django. It does not provide a complete scientific study or a universal guide on how all websites should be built.
Based on reporting from Julia Evans. This is an independent explainer, written in our own words with AI assistance; Julia Evans has not reviewed or endorsed it. Read the original for the full details.