Django validation for templates loaded via template tags

I am writing a test suite for an application.

In a number of places, I use Django for "assertTemplateUsed". This works for all templates except, as far as I can see, templates loaded via template tags (like include_tag objects).

Is there an alternative way that I claim to use a template when it is loaded through a template tag? I can of course check the lines in the template, but checking the use of the template would be a better solution.

+5
source share
1 answer

Try to catch the signal template_renderedthat is available during testing.

From the docs:

django.test.signals.template_rendered

Sent when the test system renders a template. This signal is not emitted during normal operation of a Django server – it is only available during testing.

Arguments sent with this signal:

sender
    The Template object which was rendered.
template
    Same as sender
context
    The Context with which the template was rendered. 
+2
source

All Articles