Skip to content

Instantly share code, notes, and snippets.

@cuu508
Created March 23, 2018 18:20
Show Gist options
  • Save cuu508/351bc733a0d6a7e2186cb2469f20b432 to your computer and use it in GitHub Desktop.
Save cuu508/351bc733a0d6a7e2186cb2469f20b432 to your computer and use it in GitHub Desktop.
class IncludeNode(Node):
context_key = '__include_context'
# ... constructor etc. ...
def render(self, context):
try:
# ... template gets rendered here ...
except Exception as e:
if context.template.engine.debug:
raise
template_name = getattr(context, 'template_name', None) or 'unknown'
warnings.warn(
"Rendering {%% include '%s' %%} raised %s. In Django 2.1, "
"this exception will be raised rather than silenced and "
"rendered as an empty string." %
(template_name, e.__class__.__name__),
RemovedInDjango21Warning,
)
logger.warning(
"Exception raised while rendering {%% include %%} for "
"template '%s'. Empty string rendered instead.",
template_name,
exc_info=True,
)
return ''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment