code: def get_template_debug(template_name, error):
      '''
      This structure is what Django wants when errors occur in templates.
      It gives the user a nice stack trace in the error page during debug.
      '''
      # This is taken from mako.exceptions.html_error_template(), which has an issue
      # in Py3 where files get loaded as bytes but `lines = src.split('\n')` below
      # splits with a string. Not sure if this is a bug or if I'm missing something,
      # but doing a custom debugging template allows a workaround as well as a custom
      # DMP look.
      # I used to have a file in the templates directory for this, but too many users
      # reported TemplateNotFound errors. This function is a bit of a hack, but it only
      # happens during development (and mako.exceptions does this same thing).
      #   /justification
      stacktrace_template = MakoTemplate(r)
      tback = RichTraceback(error, error.__traceback__)
      lines = stacktrace_template.render_unicode(tback=tback)
      return {
          'message': '',
          'source_lines': [
              ( '', mark_safe(lines) ),
          ],
          'before': '',
          'during': '',
          'after': '',
          'top': 0,
          'bottom': 0,
          'total': 0,
          'line': tback.lineno or 0,
          'name': template_name,
          'start': 0,
          'end': 0,
      }
docs: This structure is what Django wants when errors occur in templates.
      It gives the user a nice stack trace in the error page during debug.