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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django-template-analyzer-1.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 926ec59d97d3021441585dfee1ee35aa5926e1fa45b609572948a0c2acf06a92 |
|
MD5 | 532c0e98ba732945ee912c28f0d7f1fc |
|
BLAKE2b-256 | 61cfc625714d6e27b9b30aa55553e1c693ab574ce2ede8de0584e7157d7aa366 |
Hashes for django_template_analyzer-1.4-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4823533e09350cdfffba1ecad06ad4d0a8cd2151f9322373fa5858fa1dfee453 |
|
MD5 | b6e7e79199326373eb49fbe16596475e |
|
BLAKE2b-256 | 8fd8d4383e3880415f60ce9c6c1dd2db53a1ddbc85c06bab15b2745dd969009a |