Don't fall back to default template name if the user specified an explicit template name: fail on TemplateNotFound
@@ -147,8 +147,15 @@ def dispatch_response_handler(r):
context=EMPTY,
)
def render_root(*, part, template_name=MISSING, content_block_name=MISSING, context, **render):
+ assert part._is_bound
if template_name is MISSING:
template_name = getattr(settings, 'IOMMI_BASE_TEMPLATE', DEFAULT_BASE_TEMPLATE)
+
+ try:
+ get_template(template_name)
+ except TemplateDoesNotExist:
+ template_name = f'iommi/base_{get_style_for(part)}.html'
+
if content_block_name is MISSING:
content_block_name = getattr(settings, 'IOMMI_CONTENT_BLOCK', DEFAULT_CONTENT_BLOCK)
@@ -163,11 +170,6 @@ def render_root(*, part, template_name=MISSING, content_block_name=MISSING, cont
**context,
)
- try:
- get_template(template_name)
- except TemplateDoesNotExist:
- template_name = f'iommi/base_{get_style_for(part)}.html'
-
template_string = '{% extends "' + template_name + '" %} {% block ' + content_block_name + ' %}{{ iommi_debug_panel }}{{ content }}{% endblock %}'
return get_template_from_string(template_string).render(context=context, request=part.get_request())
