Skip to main content

Django Template Analyzer - Extract template nodes from a Django template

Project description


.. image::
.. image::
.. image::
.. image::
.. image::

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

.. code-block:: python

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]


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 .

.. include:: CHANGES.rst


* This package is based on the work of
`Django CMS <>`_.
* Many thanks to the contributors of ``cms/utils/`` / ``cms/utils/`` in Django CMS!

Release history Release notifications

This version
History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
django_template_analyzer-1.6.1-py2.py3-none-any.whl (12.1 kB) Copy SHA256 hash SHA256 Wheel py2.py3 Mar 23, 2016
django-template-analyzer-1.6.1.tar.gz (9.1 kB) Copy SHA256 hash SHA256 Source None Mar 23, 2016

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page