Skip to main content

Jinja2 Extension for template debugging.

Project description

Jinja2-template_info is Jinja2 Extension module and piece of code to generate and show some template information which could help with debuging templates.

template_info

render(template, path, **kwargs)

That is simple function, which return rendered string from Jinja2. If there is debug variable set to positive variable in kawrgs, TemplateInfoExtension is used and attributes data and template was set.

template:

template file name

path:

path or paths, where jinja could find the template

**kwargs:

data, which are send to template

>>> try:
...     from importlib.resources import files
... except ImportError:
...     from importlib_resources import files
>>> from jinja2_template_info import render
>>> path = (files('jinja2_template_info'), "./")
>>> render("test.html", path, debug=True,
...        code_variable="Variable from code")
...        # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
'<!DOCTYPE html>...</html>'

class TemplateInfoExtension(Extension)

Extension class, which append TemplateInfo instance to template in template_info variable. This class contains own Undefined class, which is use to store undefined variables names. They are in template_info.undefined.

>>> try:
...     from importlib.resources import files
... except ImportError:
...     from importlib_resources import files
>>> from jinja2 import Environment, FileSystemLoader
>>> from jinja2_template_info import TemplateInfoExtension
>>> data = {"title":"Title"}
>>> path = (files('jinja2_template_info'), "./")
>>> env = Environment(loader=FileSystemLoader(path),
...                   extensions=[TemplateInfoExtension])
>>> env.globals["template_info"].data = data.copy()
>>> env.globals["template_info"].template = "test.html"
>>> template = env.get_template("test.html")
>>> template.render(data)   # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
'<!DOCTYPE html>...</html>'

template_info.html

This file contains some macros for better html output of variables. Becouse local template variables are readed only from each template, that must be used as macro argument.

render_info(local_variables=none)

Append debug output to template. Output is labeled with section name, some sections are shown only if they are set.

Local Variables:

Variables from template, where render_info is call. Local variable could be get with template_info.context().get_exported()) call.

Template:

Template file name (template_info variable).

Input Variables:

kwargs data from render function (template_info variable).

Context:

Context content without variables. There are all functions, macros and other objects set to environment.globals.

Undefined objects:

List of undefined variables,functions, macros and other objects, which is not found and template want use it.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Jinja2-template_info-0.2.1.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

Jinja2_template_info-0.2.1-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file Jinja2-template_info-0.2.1.tar.gz.

File metadata

  • Download URL: Jinja2-template_info-0.2.1.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.6.7

File hashes

Hashes for Jinja2-template_info-0.2.1.tar.gz
Algorithm Hash digest
SHA256 2b98a52c4b0d6cb3c5c9914c1de9d033af735759a368184752da2598256bf3d2
MD5 d1d8fc5ec4c88c9c052b8361768a3613
BLAKE2b-256 e0675396368f609ef386f29bbaa3ae78c77e58ccbc9c4ea4d7d7bd52e1ce6338

See more details on using hashes here.

File details

Details for the file Jinja2_template_info-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: Jinja2_template_info-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.6.7

File hashes

Hashes for Jinja2_template_info-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2d46dea649dba0ceafda3007c91a094b38624f6382bdb3e789bc8a63d749cb9f
MD5 baac3abe414e5c4a9ee8eb1755c67d9f
BLAKE2b-256 fe1651cc9ee39553f281cf85754ea1a7880b2c5b95dfe3fe134d46b796d588df

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page