PyPugJS

raw JSON →
6.0.3 verified Fri May 01 auth: no python

PyPugJS is a Python port of the PugJS (formerly Jade) template engine. It provides a syntax adapter for Django, Jinja2, Mako, and Tornado templates. The current version is 6.0.3, with an active development cadence. Note that v6.0.0 dropped support for Python versions below 3.10.

pip install pypugjs
error ModuleNotFoundError: No module named 'pypugjs'
cause Library not installed or installed in wrong environment.
fix
Run 'pip install pypugjs' in the correct Python environment.
error ImportError: cannot import name 'Preprocessor' from 'pypugjs'
cause Incorrect import path; Preprocessor is in the jinja extension.
fix
Use 'from pypugjs.ext.jinja import Preprocessor' instead.
error TemplateSyntaxError: Unexpected token 'indent'
cause Indentation errors in .pug file, often due to mixing spaces and tabs.
fix
Ensure consistent indentation (use spaces, 2 or 4 per level).
breaking v6.0.0 dropped support for Python versions below 3.10. If you are on an older Python version, stay on v5.x.
fix Upgrade Python to 3.10+ or pin pypugjs to <6.0.0
deprecated The 'pyjade' package is deprecated in favor of 'pypugjs'. Many older tutorials reference pyjade.
fix Use pypugjs instead of pyjade
gotcha Template syntax uses significant indentation; mixing tabs and spaces can cause parse errors.
fix Use consistent spacing (spaces preferred) in .pug files

Basic Django integration with PyPugJS

from pypugjs.ext.django import PyPugJSTemplate

# Use as Django template backend:
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'OPTIONS': {
            'loaders': [
                ('django.template.loaders.cached.Loader', [
                    'django.template.loaders.filesystem.Loader',
                ]),
            ],
            'builtins': ['pypugjs.ext.django.templatetags'],
        },
    },
]