[Answer]-Django: making {% block "div" %} conditional with a conditional {% extends %}

0👍

My Solution:

{% extends x|yesno:"stamped/blank.html,stamped/home.html" %}

Where blank.html contains:

{% block results %}{% endblock %}

<!-- to allow for corrected shared rendering 
    with ajax posts and normal django rendering -->

and home.html is my standard app page with a results block to extend.

1👍

Wouldn’t this, or some variant, do?

{% if request.is_ajax %}
    {# ajax! #}
{% else %}
    {% block 'some_div' %}{% endbock %}
{% endif %}
👤Rob L

Leave a comment