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:

  1. Django cached loader get_template_sources is called
  2. Django cached loader delegates to children
  3. PyPugJS delegates to children and returns the origin(s) they return. The origins’ loader will be set to the child loader, not pypugjs.
  4. 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

Most upvoted comments

It does. pypugjs.ext.django.Loader is now a subclass of django.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.