Any way to make {% extends '...' %} conditional? - Django

ghz 1years ago ⋅ 1465 views

Question

I would like to share a template between AJAX and regular HTTP calls, the only difference is that one template needs to be served with the base.html html, the other one without.

Any idea?


Answer

Use a variable.

{% extends base_template %}

and in your view, set it to "base.html" in your view, or a new "ajax.html" file which just provides the block and nothing else.