Search code examples
pythontemplatesjinja2extends

Error Traceback in Jinja2 when Extending Template


I’m using template inheritance in jinja2 because I have a top bar in my website that I need to include in all pages. The problem is that whenever there is an error in any page the traceback always points to the line with the {% extends %} tag and I cannot locate the source of the error.

Is there a way to find out which line is causing the error (aside from reading the whole code myself) or another way to do template inheritance than {% extends %}?


Solution

  • So after trying a lot of things, I found that the best way to do this is to use iframes instead of the Jinja extend. This way, not only can I locate the source of the error, I don’t have to send the Python values I am using in the frames to each template that I am going to render. I only send them to the original class that creates the iframe template.