This is a quick question with the use of dict.keys()
I’m returning a dictionary in py file
Ex:
response['dict'] = {'a': [1,2,4], 'b': [5,6,7]}
And in the html i’m try to loop over using keys
{% if dict %}
{% for list in dict.keys() %}
list
{% endfor %}
{endif}
This is throwing an error.
TemplateSyntaxError: Could not parse the remainder: ‘keys()’ from
‘dict.keys()
Need help here. How to use this in Django?
edit:
{% if dict %}is not needed – if given context’s variable is empty (or if it’s empty dict), it silently passes: