PyPugJS doesn't work with django cached template loader
See original GitHub issue- 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.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:15 (6 by maintainers)
Top Results From Across the Web
Resetting cache for Django cached template loader
Unfortunatly, i failed to find any info on how the cache is invalidated and when and how it is reset. I want to...
Read more >pypugjs · PyPI
PyPugJS is a high performance port of PugJS for python, that converts any .pug source into different Template-languages (Django, Jinja2, Mako or Tornado)....
Read more >Enable the cached template loader when DEBUG=False if no ...
Currently enabling the cached template loader is a lot of effort, you'll have to change your settings from something like this:
Read more >settings_common.py - Blender Development
SECURITY WARNING: don't run with debug turned on in production! ... 'django.template.loaders.app_directories.Loader', ... 'pypugjs.ext.django.templatetags',.
Read more >pypugjs/ext/django/compiler.py · master · backup / pypugjs ... - GitLab
autocloseCode = 'if,ifchanged,ifequal,ifnotequal,for,block,filter,autoescape,with,trans,blocktrans,spaceless,comment,cache,localize,compress ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It does.
pypugjs.ext.django.Loader
is 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!