title: Python - Log stacktrace while Jinja2 rendering
body: <p>The following codes</p>
  
  <pre><code>import jinja2
  
  class SomeObj(object):
      def call(self):
          x = dict()
          x['raise']
  
  template = jinja2.Template('{{ obj.call() }}')
  template.render(obj=SomeObj())
  </code></pre>
  
  <p>would cause Jinja2 crashed and print the following info to console</p>
  
  <pre>
  Traceback (most recent call last):
    File "test.py", line 9, in 
      template.render(obj=SomeObj())
    File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 969, in render
      return self.environment.handle_exception(exc_info, True)
    File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 742, in handle_exception
      reraise(exc_type, exc_value, tb)
    File "", line 1, in top-level template code
    File "test.py", line 6, in call
      x['raise']
  KeyError: 'raise'
  </pre>
  
  <p>It contains call trace since the <code>render</code> function. But when I try tracking it in this way</p>
  
  <pre><code>class SomeObj(object):
      def call(self):
          try:
              x = dict()
              x['raise']
          except KeyError:
              import traceback
              traceback.print_exc()
  
  template = jinja2.Template('{{ obj.call() }}')
  template.render(obj=SomeObj())
  </code></pre>
  
  <p>I got only</p>
  
  <pre>
  Traceback (most recent call last):
    File "test.py", line 7, in call
      x['raise']
  KeyError: 'raise'
  </pre>
  
  <p>What's the proper way to get the full stacktrace in Jinja2 rendering context? Thanks in advance.</p>