Question

i am getting a dict now i want to print all true values from the dict. My dict is

[{'show_product_javadocs': False, 'show_iteration_wise_test_results': True, 'show_bug_reports': False, 'show_test_case_documentation': False, 'show_product_perldocs': False, 'show_code_coverage_reports': True, 'show_continuous_integration_test_results': True, 'show_performance_test_results': True, 'product_id_id': 1, u'id': 1L, 'show_common_java_docs': False}, {'show_product_javadocs': True, 'show_iteration_wise_test_results': True, 'show_bug_reports': True, 'show_test_case_documentation': True, 'show_product_perldocs': True, 'show_code_coverage_reports': True, 'show_continuous_integration_test_results': True, 'show_performance_test_results': True, 'product_id_id': 2, u'id': 2L, 'show_common_java_docs': True}]

but i am also getting the id and product_id_id too, because they are non zero. i am new to this and i dont know how to ignore the id and product_id_id fields. following is my template code:

{{p}}
{{p.0.show_iteration_wise_test_results}}
{% for a in p%}
{%for i in a.items %}
{% if i.1%}
{{i.0}}
{%endif%}</br> 
{%endfor%}
{%endfor%}

p is the dict which is shown above. Any help will be thankful..

Was it helpful?

Solution

Unpack the dictionary as key and value and then check the keys.

{% for a in p %}
    {% for key, value in data.items %}
        {% if key != 'id' or key != 'product_id_id' %}
            # Do your HTML operations with {{ key }} and {{ value }}
        {% endif %}
    {% endfor %}
{% endfor %}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top