Skip to main content

Django Template Analyzer - Extract template nodes from a Django template

Project description

Introduction

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 template_analyzer.djangoanalyzer import get_node_instances
from mycms.templatetags.placeholdertags import Placeholder

template = get_template("mycms/default-page.html")

placeholders = get_node_instances(template, Placeholder)
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 .

Changelog

Version 1.1: added Django 1.4 compatibility. Version 1.0: initial release.

Credits

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

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

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

django-template-analyzer-1.3.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

django_template_analyzer-1.3-py2.py3-none-any.whl (8.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-template-analyzer-1.3.tar.gz.

File metadata

File hashes

Hashes for django-template-analyzer-1.3.tar.gz
Algorithm Hash digest
SHA256 57473f255bbf083413a9bf96d03db6032eb14d51785c722f73b1d6ada9e3f868
MD5 a604a070423c2710106c9200c9bd7a1e
BLAKE2b-256 700dcd8626e0be128c3895d28b5c5a5410575da33c7d26a83b2fadd77c825581

See more details on using hashes here.

File details

Details for the file django_template_analyzer-1.3-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_template_analyzer-1.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d4deac989d34182d8b78770d37cd0a1d97bbe09360c326e5aa4461bc677c7e68
MD5 67f44f5f6acbdc3d953e1db9b01b17a3
BLAKE2b-256 3d051bc874f8d411f0a4395246636febe0f824bc5938b32054409a98c91cd2aa

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