I am trying to create a template that will only render selected values
of an unknown number of dictionary keys which follow a certain pattern.
This is the form of the dictionary in context:
{'pets':{'dog0':'Rover','dog1':'Spike','cat0':'Fang'}}
The pet dogs can go from dog0, dog1, dog2,...dogn. The same applies to
cats.
The following Pseudo code illustrates my desire to only select dogs
from the dictionary not knowing how many there will be and render their
values:
{% for pet in pets.keys %}
{% if_key_fits_pattern "dog\d" %}
<p>{{pet key}}: {{pet value}}</p>
{% endif_key_fits_pattern %}
{% endfor %}
I have tried a number of ways of doing this but can't come up with a
solution. I don't think pre-processing the data will help since the
template still doesn't know how many keys there will be. Changing the
structure of the data is not possible.
Does anyone know how to test each key to determine if the one desired
has been found and render its value?
Thanks in advance.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---