#30425: Handle `jinja2.TemplateSyntaxError` when rendering a template with or
without a source.
---------------------------------+------------------------------------
     Reporter:  Daniel Hahler    |                    Owner:  nobody
         Type:  Bug              |                   Status:  new
    Component:  Template system  |                  Version:  master
     Severity:  Normal           |               Resolution:
     Keywords:                   |             Triage Stage:  Accepted
    Has patch:  0                |      Needs documentation:  0
  Needs tests:  0                |  Patch needs improvement:  0
Easy pickings:  0                |                    UI/UX:  0
---------------------------------+------------------------------------

Comment (by Daniel Hahler):

 Indeed I forgot to mention that I've also wrapped `render` in the first
 place.

 Just for reference, the patch for `render` for django-jinja:

 {{{
 diff --git i/django_jinja/backend.py w/django_jinja/backend.py
 index 7663186..ffc64c7 100644
 --- i/django_jinja/backend.py
 +++ w/django_jinja/backend.py
 @@ -69,6 +69,8 @@ def render(self, context=None, request=None):
          context = base.dict_from_context(context)

          if request is not None:
 +            # import pudb; pu.db
 +            __import__('pdb').set_trace()
              def _get_val():
                  token = csrf.get_token(request)
                  if token is None:
 @@ -103,7 +105,12 @@ def dicts(self):
                                             template=self,
                                             context=context)

 -        return mark_safe(self.template.render(context))
 +        try:
 +            return mark_safe(self.template.render(context))
 +        except jinja2.TemplateSyntaxError as exc:
 +            new = TemplateSyntaxError(exc.args)
 +            new.template_debug = get_exception_info(exc)
 +            six.reraise(TemplateSyntaxError, new, sys.exc_info()[2])
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30425#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.9b06386a3da6bf66e83b5167b4e6211a%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to