I've got the following QueryDict object in my request.session.
<QueryDict: {u'category': [u'44', u'46'], u'cityID': [u'null'], u'countryCode': [u''], u'mapCenterLng': [u'2.291300800000009'], u'mapZoom': [u'12'], u'mapCenterLat': [u'47.10983460000001'], u'price_range': [u''], u'textbox': [u'']}>
In a template try to get the category array using:
{{request.session.lastrequest.category}}
but this gives me only the last value of the array. How can I get the entire array?
Thanks
Jul
You can't. You need to call .getlist('category')
, but you can't call methods with a parameter 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 %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With