Skip to main content

django-template-analyzer

https://github.com/edoburu/django-template-analyzer/actions/workflows/tests.yaml/badge.svg?branch=master https://img.shields.io/pypi/v/django-template-analyzer.svg https://img.shields.io/badge/wheel-yes-green.svg https://img.shields.io/codecov/c/github/edoburu/django-template-analyzer/master.svg

The template_analyzer package offers an API to analyze the Django template structure. It can be used to find nodes of a particular type, e.g. to do automatic detection of placeholder tags.

Supported features

The scanner finds tags in various situations, including:

  • Extend nodes

  • Include nodes

  • Overwritten blocks with new definitions

  • Blocks with or without {{ block.super }}

  • Reorganized blocks

  • Ignoring nodes outside blocks in extending templates

  • Handling multiple levels of super includes

The returned nodes are provided in a natural ordering, as they would be expected to appear in the outputted page.

While Django offers a template.nodelist.get_nodes_of_type() function, this function does not produce the same results.

API example

from django.template.loader import get_template
from mycms.templatetags.placeholdertags import Placeholder
from template_analyzer.djangoanalyzer import get_node_instances

# Load a Django template
template = get_template("mycms/default-page.html")

# Find all tags in the template:
placeholders = get_node_instances(template, Placeholder)

# Read information from the template tag themselves:
# (this is an example, accessing a custom method on the Placeholder object)
placeholder_names = [p.get_name() for p in placeholders]

Installation

First install the module, preferably in a virtual environment. It can be installed from PyPI:

pip install django-template-analyzer

Or the current folder can be installed:

pip install .

Credits

  • This package is based on the work of Django CMS.

  • Many thanks to the contributors of cms/utils/placeholder.py / cms/utils/plugins.py in Django CMS!

Release files for django-template-analyzer 2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-template-analyzer 2.1
File Size Uploaded
django-template-analyzer-2.1.tar.gz 9.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-template-analyzer 2.1
File Interpreter ABI Platform
django_template_analyzer-2.1-py3-none-any.whl Python 3 none any Details

Total release size: 20.4 kB

Release files / django-template-analyzer-2.1.tar.gz

Download URL django-template-analyzer-2.1.tar.gz
Size 9.5 kB
Tags Source
SHA-256 checksum
How to use checksums
aacacf114a23f65b3f967319fb49284b413a9596652bc6594b63aba82db06b89
BLAKE2b-256 checksum
How to use checksums
2e6a3b16854a12743c0896b9837eb338537a6dbc47b01c897f8410814c08cfdc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.13

Release files / django_template_analyzer-2.1-py3-none-any.whl

Download URL django_template_analyzer-2.1-py3-none-any.whl
Size 10.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f528ee9712c508bdec31f36a57a69c85a704b3df723454cc43786af908b758cb
BLAKE2b-256 checksum
How to use checksums
b194b6bc4929010486826b6c750b9a32bc87a7d6291c3a2b51d836c154ce74c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.13

Release history Release notifications | RSS feed

This release

2.1 This release

2 release files

2.0

2 release files

1.6.2

2 release files

1.6.1

2 release files

1.6

2 release files

1.5

2 release files

1.4

2 release files

1.3

2 release files

1.2

1 release file

1.1.0

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page