Reputation: 2661
I would like to know if a session object in flask can be a list, e.g: I have a form where I submit a fruit, and assign it to a session variable "session['fruit']", how can I iterate over that (if possible), like when I have a normal list:
fruits = ['Apple', 'Strawberry', 'Watermelon', 'Banana']
{% for f in fruits %}
print(f)
{% endfor %}
I would like to do that with a session variable, as I already said, if possible.
Upvotes: 0
Views: 1605
Reputation: 20709
The session variable, session
, is part of the Jinja2 context Flask provides on each request. To iterate over one of its keys:
{% for fruit in session['fruits'] %}
{{ fruit }}
{% endfor %}
Upvotes: 2