Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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


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', [

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: 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.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

tjwalchcommented, Jun 17, 2019

It does. pypugjs.ext.django.Loader is now a subclass of django.template.loaders.cached.Loader

snarfedcommented, May 10, 2019

@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!

Read more comments on GitHub >

github_iconTop 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 > - 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/ · master · backup / pypugjs ... - GitLab
autocloseCode = 'if,ifchanged,ifequal,ifnotequal,for,block,filter,autoescape,with,trans,blocktrans,spaceless,comment,cache,localize,compress ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found