Django middleware for request ID tracking

Adding unique request IDs helps trace logs across distributed systems. I generate a UUID for each request and attach it to both the request object and response headers. I also add it to the logging context so all log entries for that request include t

Avoid caching sensitive pages in Turbo Drive

Turbo’s page cache is great until you have sensitive screens (account settings, billing) where the browser back button might show stale content. I handle this by setting cache-control headers and, for specific actions, disabling Turbo caching via turb

Turbo Frames: scoped navigation inside a sidebar

You can build rich UIs by scoping navigation to a frame (e.g., a sidebar). Links inside the sidebar update only that frame while the main content stays put. This is great for filters and settings panels.

Django model meta options for database optimization

Model Meta class controls database behavior. I use ordering for default query ordering, indexes for database indexes, and unique_together for composite uniqueness constraints. The db_table option customizes table names. For large tables, managed=False

Django internationalization and localization

Django's i18n framework supports multiple languages. I mark strings for translation with gettext() or _(). The makemessages command extracts strings to .po files. Translators fill in translations, then compilemessages creates binary .mo files. I use {

Action Mailer Delivery Observability Hook

Email issues are painful in production. Subscribe to mailer notifications and log message IDs, recipients, and durations. This gives you a lightweight audit trail without adding a heavy dependency.

Database “Last Seen” without Hot Row Updates

Updating last_seen_at on every request creates hot rows and write amplification. Instead, track last seen in Redis and periodically flush to DB, or only write when the value meaningfully changes.

Runtime validation for request bodies (Zod)

TypeScript only protects you at compile time; your API still receives untrusted JSON from the internet. I lean on Zod as the source of truth for parsing + validation so runtime and types stay aligned. The big win is that I don’t try to validate ‘every

Django custom decorators for view logic

Custom decorators encapsulate reusable view logic. I use functools.wraps to preserve function metadata. For class-based views, I use method_decorator. Common patterns include permission checks, rate limiting, or request validation. Decorators can modi

Stimulus: keyboard shortcuts that work with Turbo navigation

Keyboard shortcuts improve power-user workflows, but they must survive Turbo navigation. Attach on connect/disconnect, avoid global leaks, and scope shortcuts to the page/component.

Next.js middleware for auth gating

Protecting routes at the middleware layer prevents a whole class of ‘oops, we forgot to check auth on one page’ bugs. middleware.ts runs before rendering, so unauthenticated users get redirected early and you don’t waste work. I keep the logic simple:

Django database indexes for query performance

Database indexes dramatically speed up queries. I add indexes to frequently-filtered fields via db_index=True or Meta.indexes. Compound indexes help queries filtering on multiple fields together. For text search on PostgreSQL, I use GinIndex with Sear