Django: How do I get an array from a QueryDict in a template?
I needed access to a QueryDict too, so I added a filter and it worked for my needs.
Wherever you registered your app filters:
#/templatetags/app_filters.py
from django import template
register = template.Library()
# Calls .getlist() on a querydict
# Use: querydict | get_list {{ querydict|get_list:"itemToGet" }}
@register.filter
def get_list(querydict, itemToGet ):
return querydict.getlist(itemToGet)
In template:
{% load app_filters %}
{% for each in form.data|get_list:"itemYouAreInterestedIn" %}
{{each}}
{% endfor %}
You can't. You need to call .getlist('category')
, but you can't call methods with a parameter in a template.