Skip to main content

Django Template Analyzer - Extract template nodes from a Django template

Project description

django-template-analyzer
========================

.. image:: https://travis-ci.org/edoburu/django-template-analyzer.svg?branch=master
:target: http://travis-ci.org/edoburu/django-template-analyzer
.. image:: https://img.shields.io/pypi/v/django-template-analyzer.svg
:target: https://pypi-hypernode.com/pypi/django-template-analyzer/
.. image:: https://img.shields.io/pypi/dm/django-template-analyzer.svg
:target: https://pypi-hypernode.com/pypi/django-template-analyzer/
.. image:: https://img.shields.io/badge/wheel-yes-green.svg
:target: https://pypi-hypernode.com/pypi/django-template-analyzer/
.. image:: https://img.shields.io/pypi/l/django-template-analyzer.svg
:target: https://pypi-hypernode.com/pypi/django-template-analyzer/

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]

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 .

.. include:: CHANGES.rst

Credits
=======

* This package is based on the work of
`Django CMS <http://www.django-cms.org>`_.
* Many thanks to the contributors of ``cms/utils/placeholder.py`` / ``cms/utils/plugins.py`` in Django CMS!

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.6.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

django_template_analyzer-1.6-py2.py3-none-any.whl (9.6 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

File hashes

Hashes for django-template-analyzer-1.6.tar.gz
Algorithm Hash digest
SHA256 7300624e5154fba08553f3e158059397fcd34bb6fa05ace595234066aa0b6038
MD5 e187869f73b47620e5c0fc0c16ecb73e
BLAKE2b-256 a49f60e8813414cf864f4fd23c771d57df87aaa1d2099cf9bcd494b140773ec0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_template_analyzer-1.6-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 47ff7c586fe0953d5c80cb5f9b2c3c8d572bdd4ff931f09675849c7e0206a927
MD5 b09d34616993a7f0ed925ec3c197c6aa
BLAKE2b-256 235ba488cdc54870468678ddd52cbb2888bd933706c298425e962b8521b74317

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