template tag, which makes it easier to iterate over multiple lists
simultaneously (acting similarly to Python's `zip`).
multiforloop allows this Python idiom to be used in django templates:
for x,y in zip(x_list, y_list):
print x,y
Normally, to iterate over multiple lists simultaneously in django templates,
the lists must be zipped in the view and passed in as an extra context
variable. When this is the only extra processing needed in a view (eg. with
generic views), this can result in a fair bit of unneeded boilerplate code.
##Usage
Rendering this template
{% load multifor %}
{% for x in x_list; y in y_list %}
{{ x }}:{{ y }}
{% endfor %}
with this context
context = {
"x_list": ('one', 1, 'carrot'),
"y_list": ('two', 2, 'orange')
}
will output
one:two
1:2
carrot:orange
The multifor tag library also includes a `for_longest` tag that functions
similarly to izip_longest from Python's itertools library. Whereas the
normal for loop will truncate all inputs to the length of the shortest,
for_longest will iterate over all values of the longest, filling any shorter
inputs with the value in settings.TEMPLATE_STRING_IF_INVALID ('' by default).
Observe the difference:
Rendering this template
{% load multifor %}
{% for x in x_list; y in y_list %}
{{ x }}:{{ y }}
{% endfor %}
with this context
context = {
"x_list": ('one', 1, 'carrot'),
"y_list": ('two', 2)
}
will output
one:two
1:2
While rendering this template
{% load multifor %}
{% for_longest x in x_list; y in y_list %}
{{ x }}:{{ y }}
{% endfor %}
with the same context
context = {
"x_list": ('one', 1, 'carrot'),
"y_list": ('two', 2)
}
will output
one:two
1:2
carrot:
## Installation
1. pip install django-multiforloop
2. Include 'multiforloop' in your settings.py's list of installed apps
3. Add `{% load multifor %}` to the top of any templates which use the multiforloop
Metadata
Release files for django-multiforloop-patched 0.2.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 | Actions |
|---|---|---|---|---|
| django-multiforloop-patched-0.2.0.tar.gz | 4.0 kB | Without provenance | Details for django-multiforloop-patched-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django-multiforloop-patched-0.2.0.macosx-10.9-intel.tar.gz | Details for django-multiforloop-patched-0.2.0.macosx-10.9-intel.tar.gz |
Total release size: 11.4 kB
Release files / django-multiforloop-patched-0.2.0.tar.gz
| Download URL | django-multiforloop-patched-0.2.0.tar.gz |
|---|---|
| Size | 4.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1f42cddf2707f91f958e29492a7be279cdf5dcaaff0cbc69ef06dcb424237cac
|
|
BLAKE2b-256 checksum How to use checksums |
1d99a2b13b36939f97ad3e0418bf09fd30aaf262619ad929ebc5d28f18858059
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / django-multiforloop-patched-0.2.0.macosx-10.9-intel.tar.gz
| Download URL | django-multiforloop-patched-0.2.0.macosx-10.9-intel.tar.gz |
|---|---|
| Size | 7.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0ef2de8989935582999aff682f322ebb8499c426330ec66019624f16bd0fb49d
|
|
BLAKE2b-256 checksum How to use checksums |
dfd58547a691a5ab270377fc16471985fb70cd8adc2c4978a562cb180aa0e16c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-multiforloop-patched 0.2.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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.