pypugjs: PyPugJS doesn't work with django cached template loader
- pypugjs version: 5.7.2
- Django version: 1.11.12
- Python version: 2.7
- Operating System: Linux
Description
If you want to use django cached loader with pypugjs, you’d have the following template loader settings:
('django.template.loaders.cached.Loader', [
('pypugjs.ext.django.Loader', [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
]),
])
With pypugjs 4.2.2 this worked fine, but with 5.7.2 it doesn’t, because the pug processing of contents never happens.
Here’s the code in 4.2.2: https://github.com/kakulukia/pypugjs/blob/4.2.2/pypugjs/ext/django/loader.py#L101 The loading of the template uses child loaders to get contents, then processes them, then returns a template with an origin and the processed contents.
In 5.7.2 this process has been updated to work with the new django get_template_sources and get_contents methods. In my example, the following will happen:
- Django cached loader get_template_sources is called
- Django cached loader delegates to children
- PyPugJS delegates to children and returns the origin(s) they return. The origins’ loader will be set to the child loader, not pypugjs.
- Django cached loader get_contents is called with the returned origin. This results in the origin’s loader (for example, the filesystem loader) returning an unprocessed pug string rather than going through the PyPugJS get_contents() method which would have converted the pug to django-compatible html.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 2
- Comments: 15 (6 by maintainers)
Commits related to this issue
- django docs: mention not to wrap with django's caching template loader for #44 — committed to snarfed/pypugjs by snarfed 5 years ago
- django docs: mention not to wrap with django's caching template loader for #44 — committed to snarfed/pypugjs by snarfed 5 years ago
- django docs: mention not to wrap with django's caching template loader (#52) for #44 — committed to kakulukia/pypugjs by snarfed 5 years ago
It does.
pypugjs.ext.django.Loaderis now a subclass ofdjango.template.loaders.cached.Loader@tjwalch ah! good catch, we were doing exactly that. apologies for the false alarm! i believe removing that fixes it for us. i’ll post back later when i know more. thanks, great guess!
Actually PyPugJS is also caching templates, so the need for the cached loaded should not exist.