Skip to main content
django-multiforloop provides an enhancement to django's builtin forloop
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

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)

Source distribution for django-multiforloop-patched 0.2.0
File Size Uploaded
django-multiforloop-patched-0.2.0.tar.gz 4.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-multiforloop-patched 0.2.0
File Interpreter ABI Platform
django-multiforloop-patched-0.2.0.macosx-10.9-intel.tar.gz Details

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

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page