Udders
Udders

Reputation: 6986

Look for value in array python/flask

I am working with Python and Flask at the moment, and I wanting to do a check in my template for if a value is contained in an array that is passed to template the code that build the array looks like this,

statuses = {}
statuses['personal_status'] = ['Pending', 'Cancelled']
statuses['planner_status'] = ['Pending', 'RP_Approved', 'RP_Declined', 'Cancelled', 'Approved']
statuses['approver_status'] = ['Approved', 'Mgr_Declined']

In my template I am wanting search statuses.personal_status to see if a value is present in the array and if so show some other DOM elements, is this possible?

Upvotes: 1

Views: 2398

Answers (1)

René Jahn
René Jahn

Reputation: 1213

You might consider the following code in your template:

<div>
{% if 'specific_status' in statuses.personal_status %}
    yay
{% endif %}
</div>

Upvotes: 4

Related Questions