Skip to main content

Django Template Analyzer - Extract template nodes from a Django template

Project description

django-template-analyzer

https://travis-ci.org/edoburu/django-template-analyzer.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!

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

Uploaded Source

Built Distribution

django_template_analyzer-1.6.2-py2.py3-none-any.whl (11.3 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: django-template-analyzer-1.6.2.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.10.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/2.7.17

File hashes

Hashes for django-template-analyzer-1.6.2.tar.gz
Algorithm Hash digest
SHA256 25d8349f7c48580343ba2b548584ba67ca993627d7e9cd42c04dafa06d6f1c09
MD5 4fdaa5a8aba454e024f891181624eb21
BLAKE2b-256 ecf75689e24a4c77abdd816c1ae5f247543cd07b2bc9d7d1d204a3c4b15b9321

See more details on using hashes here.

File details

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

File metadata

  • Download URL: django_template_analyzer-1.6.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.10.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/2.7.17

File hashes

Hashes for django_template_analyzer-1.6.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ff981cda6ffe2a35affd4e6b57c95e4e5f041576bd81d0f614351d3c564221e0
MD5 79d93b7cf045e6694376ca9908d609b5
BLAKE2b-256 ade2cbae7c7e7a97d1c56ab5d82eb2c72f55d092ee93b56ae078bdfb7397e5d7

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