There is currently no great way to do tree structures in Django templates.
Thus, this module contains a tag for rendering trees from sequences.
For this, a method for recursion is given, as well as for defining start and end
markers. A full example of the syntax of this template tag is the following:
{% load treetag %}
{% tree item_seq %}
<ul> {# indentation section #}
{% for item in tree %} {# item start #}
<li>{{ item.description }}
{% subtree item.sub_seq %} {# subtree renders same as whole tree #}
</li>
{% endfor %} {# item end #}
</ul> {# outdentation section #}
{% endtree %}
The syntax defined here thus has two special tags and splits into three
sections. The sections are:
1. The tree indentation section
2. The tree item section
3. The tree outdentation section
Start a tree by enclosing the whole of the tree code with a `tree`/`endtree` tag
pair. The `tree` tag needs to receive one argument, a sequence of items. This
sequence will be available inside the tree as a variable named `tree`. The
renaming is necessary so we can map the sequence in subtrees to the same name.
The three sections are separated by a `for`-loop looping over the items.
In the tree indentation section, place everything that belongs to the 'head' of
a tree, like the start tags of a list or a table.
In the item section, place everything that renders the item, as well as the
special recursive tag that renders the subtree. The `subtree` tag simply takes
Finally in the outdentation section, place everything that closes the tree, like
the closing of the list or table tags and any footer material for the tree.
Nested trees are not supported at the moment (i.e. placing a `tree` section
inside of another `tree` section).
Alternatives are:
* django-mptt: https://github.com/django-mptt/django-mptt/
* self-made tree unrolling: https://stackoverflow.com/questions/32044/how-can-i-render-a-tree-structure-recursive-using-a-django-template
* hacking the `include` tag: http://blog.elsdoerfer.name/2008/01/22/recursion-in-django-templates/ (please don't do this!)
* for simpler cases, the builtin `unordered-list` filter might be sufficient: https://docs.djangoproject.com/en/1.5/ref/templates/builtins/#unordered-list
Thus, this module contains a tag for rendering trees from sequences.
For this, a method for recursion is given, as well as for defining start and end
markers. A full example of the syntax of this template tag is the following:
{% load treetag %}
{% tree item_seq %}
<ul> {# indentation section #}
{% for item in tree %} {# item start #}
<li>{{ item.description }}
{% subtree item.sub_seq %} {# subtree renders same as whole tree #}
</li>
{% endfor %} {# item end #}
</ul> {# outdentation section #}
{% endtree %}
The syntax defined here thus has two special tags and splits into three
sections. The sections are:
1. The tree indentation section
2. The tree item section
3. The tree outdentation section
Start a tree by enclosing the whole of the tree code with a `tree`/`endtree` tag
pair. The `tree` tag needs to receive one argument, a sequence of items. This
sequence will be available inside the tree as a variable named `tree`. The
renaming is necessary so we can map the sequence in subtrees to the same name.
The three sections are separated by a `for`-loop looping over the items.
In the tree indentation section, place everything that belongs to the 'head' of
a tree, like the start tags of a list or a table.
In the item section, place everything that renders the item, as well as the
special recursive tag that renders the subtree. The `subtree` tag simply takes
Finally in the outdentation section, place everything that closes the tree, like
the closing of the list or table tags and any footer material for the tree.
Nested trees are not supported at the moment (i.e. placing a `tree` section
inside of another `tree` section).
Alternatives are:
* django-mptt: https://github.com/django-mptt/django-mptt/
* self-made tree unrolling: https://stackoverflow.com/questions/32044/how-can-i-render-a-tree-structure-recursive-using-a-django-template
* hacking the `include` tag: http://blog.elsdoerfer.name/2008/01/22/recursion-in-django-templates/ (please don't do this!)
* for simpler cases, the builtin `unordered-list` filter might be sufficient: https://docs.djangoproject.com/en/1.5/ref/templates/builtins/#unordered-list
Metadata
Release files for django-tree-tag 1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django-tree-tag-1.0.tar.gz | 3.7 kB | Without provenance | Details |
Release files / django-tree-tag-1.0.tar.gz
| Download URL | django-tree-tag-1.0.tar.gz |
|---|---|
| Size | 3.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f603fd599f592fd5f11008bac1cc0c442819df79ef55d83873226a043ba8ba3d
|
|
BLAKE2b-256 checksum How to use checksums |
044ceb5db1ecd016c5a85a1e272ba506d266e0ce5faed4eeceb0c5ee133b3719
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-tree-tag 1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.