A set of simple tools that will make your life easier in django templates. Based on great django-classytags library.
Installation
Install the package
$> pip install django-template-goodies
put “template_goodies” into INSTALLED_APPS.
Usage: render_with & def_block and use_block
This is sort of macro-like solution allowing you to define base template that looks always the same, and fill just a “block” inside it differently.
Assuming you have partial template person_wrapper.html:
{% load goodies %}
<div class="person-wrapper">
<div class="first-name">{{ first_name }}</div>
{% use_block "block" %}
</div>
You can use it in following way:
{% load goodies %}
{% render_with "person_wrapper.html" first_name="First" last_name="Last" %}
{% def_block "block" %}
<div class="last-name">{{ last_name }}</div>
{% end %}
{% end %}
This invocation will substitude “{% use_block “block” %}” in person_wrapper.html with the contents within “{% def_block …. %}” and “{% end %}” insidee “render_with”. So the outcome of above will be more or less:
<div class="person-wrapper">
<div class="first-name">First</div>
<div class="last-name">Last</div>
</div>
Another example with tables, table.html:
{% load goodies %}
<table class="{{ opts.table_class }}">
<thead>
<tr>
{% use_block "headers" %}
</tr>
</thead>
<tbody>
{% for row in object_list %}
<tr>
{% use_block "row" %}
</tr>
{% endfor %}
</tbody>
</table>
can be used in following way:
{% render_with "table.html" object_list=people %}{% def_block "headers" %}
<td>ID</td>
<td>First name</td>
<td>Last Name</td>
<td>Age</td>
{% end %}{% def_block "row" %}
<td>{{ forloop.counter }}</td>
<td>{{ row.first_name }}</td>
<td>{{ row.last_name }}</td>
<td>{{ row.age }}</td>
{% end %}{% end %}
Usage: dict
Updates or creates dictionary inside template. You can use all kinds of filters on variable if you need:
{% load goodies %}
{% dict opts name="first"|title %}
{% dict opts last_name="last" value=opts.name %}
{{ opts.first }} - {{ opts.last_name}} || {{ opts.value }}
The outcome will be more or less following:
First - last || first
Requirements
django-classytags
Metadata
Release files for django_template_goodies 0.1.5
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 | Actions |
|---|---|---|---|---|
| django_template_goodies-0.1.5.tar.gz | 2.9 kB | Without provenance | Details for django_template_goodies-0.1.5.tar.gz |
Release files / django_template_goodies-0.1.5.tar.gz
| Download URL | django_template_goodies-0.1.5.tar.gz |
|---|---|
| Size | 2.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
415f322e8ba9a69ff18a4a698928a12ea654541ae1ba3493950472d41cf05f79
|
|
BLAKE2b-256 checksum How to use checksums |
d02350962757f1de9d7cd66fe7ed61ca965169d032af24a2a7cc4da05da3e371
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django_template_goodies 0.1.5
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.