The Python Oracle

Jinja2 shorthand conditional

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Hypnotic Puzzle4

--

Chapters
00:00 Jinja2 Shorthand Conditional
00:21 Accepted Answer Score 566
00:33 Answer 2 Score 12
00:44 Thank you

--

Full question
https://stackoverflow.com/questions/1421...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #jinja2 #conditionaloperator

#avk47



ACCEPTED ANSWER

Score 566


Yes, it's possible to use inline if-expressions:

{{ 'Update' if files else 'Continue' }}



ANSWER 2

Score 12


Alternative way (but it's not python style. It's JS style)

{{ files and 'Update' or 'Continue' }}