I found some answer to my question, so I post it here for future confirmation.
If I use a filter template_exists like this
{% if 'profile/header.html'|template_exists %} {% include 'profile/header.html' %} {% else %} {% include 'common/header.html' %} {% endif %}
and if profile/header.html does not exist, then TemplateDoesNotExist gets a strange distribution when the page loads, and I get a server error. However, if instead I use this in my template:
{% with 'profile/header.html' as var_templ %} {% if var_templ|template_exists %} {% include var_templ %} {% else %} {% include 'common/header.html' %} {% endif %} {% endwith %}
Then it works like a charm!
Obviously i could use
django.template.loader.select_template(['profile/header.html','common/header.html'])
in view (from this SO answer ). But I use CBV, which I would like to keep fairly universal, and this was called from the main template. And also I thought that it would be nice if my site worked, if for some reason these applications are down. If this seems silly to you, please leave a comment (or an even better answer).
source share