Sept. 29, 2024

Ensuring a block is overridden in a Django template

Ensuring a block is overridden in a Django template

Neat Django trick by Tom Carrick: implement a Django template tag that raises a custom exception, then you can use this pattern in your templates:

{% block title %}{% ensure_overridden %}{% endblock %}

To ensure you don't accidentally extend a base template but forget to fill out a critical block.

Via Carlton Gibson

Tags: django, python