0

i have some issue with my application. Here's my code :

view.py

dict_test = {}
for result in myMongoDbRequest:
  dict_in_dict = {}
  for otherResult in result["myList"]:
    dict_in_dict[otherResult["1"]] = [otherResult["2"], otherResult["3"]]
  dict_test[result["name"]] = [result["value1"], dict_in_dict]

template_filter.py

@register.filter
def get_in_list(list, index):
    return list[index]

template.html

{% for key, values in dico_test.items %}
<div id="div{{key}}">
   {% for key, value in values|get_in_list:1.items %}
   <div class="{{ key }}">
      {{ value }}
   </div>
   {% endfor %}
</div>

{% endfor %}

Obviously, the .items in the template is incorrect, but i wonder how to resolve this problem ? Maybe with another filter ? I try several things but nothing works, like this filter :

@register.filter
def convert_in_dict(a):
    return vars(a)
{% for key, value in values|get_in_list:5|convert_in_dict.items %}

But django raise Could not parse the remainder: '.items' from 'values|get_in_list:1|convert_in_dict.items'

Abdul Aziz Barkat
  • 17,586
  • 2
  • 14
  • 28
UnPapeur
  • 23
  • 4

0 Answers0