Skip to content

Support for non-Django template systems #168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

nyergler
Copy link
Contributor

Django 1.2 introduced support for non-Django template systems. Unfortunately the instrumented test renderer is still Django specific. This branch updates the Template panel monkey patching to wrap template lookup and decorate the Template class' render method to emit the correct signal. This allows DjDT to work with non-Django template systems (tested with Mako templates).

nyergler added 2 commits May 26, 2011 08:49
find_template_and_decorate will decorate the render method of Template
classes in order to emit signals needed by Django Debug Toolbar.
@ivirabyan
Copy link

I want it too

@aaugustin
Copy link
Contributor

This code has been refactored since you filed the pull request. Do you know if the problem still exists in master?

@aaugustin
Copy link
Contributor

After further code inspection, I believe the master branch doesn't support this use case yet.

@aaugustin
Copy link
Contributor

https://github.com/jbalogh/jingo should allow to reproduce this issue without writing too much code.

@aaugustin
Copy link
Contributor

I spent some time on this issue today. Django's support for other template languages is documented here:
https://docs.djangoproject.com/en/dev/ref/templates/api/#using-an-alternative-template-language

The debug toolbar performs two monkey-patches:

  • It modifies Template.__init__ to store the origin attribute. This isn't useful anymore in Django >= 1.7 because Django does it by itself.
  • It modifies Template.render to send the template_rendered signal before rendering a template. I could add this feature to Django, too.

Some libraries designed to integrate third-party template languages with Django have these features built-in:
https://github.com/jbalogh/jingo/blob/b40ccfc/jingo/__init__.py#L188-L193

If we look at the implementation, Django goes through through each template loader and calls it with the template name. The template object is returned by load_template. We can override that method. However, at this point, the template is already initialized. All we can do is alter the behavior of its render method.

@tim-schilling
Copy link
Member

Jinjo now supports working with the debug toolbar. I found another library that I was able to reproduce the issue with, django-jinja2.

Also, for future/other readers the issue isn't that an error occurs, it's that the template panel doesn't contain any information about the template or the context passed to it.

@aaugustin
Copy link
Contributor

I'm going to close this in favor of #693. Sorry it didn't get merged.

@aaugustin aaugustin closed this Mar 2, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants