2π
Your base template should provide defaults for most or all pages, but make it possible to override the default in cases where itβs less than ideal.
Here, put the base template message code into a named block.
{% block default_messages %}
{% if messages %}
{% for message in messages %}
<div class="alert alert-{{ message.tags }} alert-dismissible fade show" role="alert" id="message">
{{ message }}
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
{% endfor %}
{% endif %}
{% endblock default_messages %}
Now in any page where you find that the default is undesirable, you can override it. In page_template.html
:
{% block default_messages %}
<!-- delete the default, i.e. omit { { block.super } } -->
{% endblock default_messages %}
and handle messages
explicitly, elsewhere in page_template.html
, perhaps with a %include
if the block of message code is going to be useful in multiple pages.
π€nigel222
- [Answered ]-Can I extend parent's class list attribute on class level?
- [Answered ]-Django Pinax β How to use apps in other projects, not cloned Pinax projects?
- [Answered ]-Django static files β images detected but not css
Source:stackexchange.com