django-commons / django-debug-toolbar

A configurable set of panels that display various debug information about the current request/response.
https://django-debug-toolbar.readthedocs.io
BSD 3-Clause "New" or "Revised" License
8.11k stars 1.05k forks source link

Jinja2 Support Broken #1881

Open ae99 opened 9 months ago

ae99 commented 9 months ago

Hey! Spent some time trying to get Jinja2 templates to appear in the debug toolbar correctly. Templates tab was simply saying "No Templates". This had me stumped as there's a test case for this in the codebase.

Upon some further digging, I think the Jinja2 test in tests/templates/jinja2/basic.jinja is actually being rendered as a Django template, not through Jinja 2. Modifying that template to contain:

{% extends 'base.html' %}
{% block content %}Test for {{ title }} (Jinja)
{% for i in range(10) %}{{ i }}{% endfor %}
{% endblock %}

Causes the test to fail with Django throwing django.template.exceptions.TemplateSyntaxError - even though this is valid Jinja and Django's template shouldn't be involved, so this test isn't actually using Jinja2.


It appears if you are using Jinja2 to render templates, DDT isn't able to pick up what goes on inside them, at least with default configurations. Any pointers on how I could get this working for myself would be great!

matthiask commented 9 months ago

That's surprising! We should definitely add some Jinja2-only syntax to the basic.jinja template.

I did some work here https://github.com/jazzband/django-debug-toolbar/pull/1882 but yeah, it seems that the tracking is broken. I wonder when that happened!