How to use this solution https://stackoverflow.com/a/10067749/604240 in jinja 2 template?
Asked
Active
Viewed 806 times
2 Answers
1
I agree my question was due to lack of knowledge than problem. Eventually I figured it out how to achieve it. Basically I didn't know how to link loop from python code to query so it's available to Jinja2 template.
Although correct solution might be to use map() with callback function https://developers.google.com/appengine/docs/python/ndb/queryclass#Query_map but I am using temporary solution which is working for me for now.
query = Image.query()
query2 = query.filter(Image.is_slider == 'yes')
for item in query2:
item.parent = item.key.parent().get()
and in template
{% for item in query2 %}
<img src="{{ item.url }}=s1000" alt="{{ item.title }}" title="{{ item.title }}" />
<h2>{{ item.title }}</h2>
<h3>{{ item.gallery }}</h3>
<a href="/gallery/{{ item.parent.slug }}">Go to gallery</a>
{% endfor %}

fusionstrings
- 1,025
- 2
- 13
- 23
0
Why don't you just try {{ item.key.parent().get().slug }}
on your jinja2 template (assuming that slug is a property of your Gallery entity).