python ternary in jinja2 gives TemplateSyntaxError: tag name expected
Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Cosmic Puzzle
--
Chapters
00:00 Question
00:47 Accepted answer (Score 20)
01:11 Answer 2 (Score 2)
01:31 Thank you
--
Full question
https://stackoverflow.com/questions/3591...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #css #python27 #jinja2
#avk47
    --
Music by Eric Matyas
https://www.soundimage.org
Track title: Cosmic Puzzle
--
Chapters
00:00 Question
00:47 Accepted answer (Score 20)
01:11 Answer 2 (Score 2)
01:31 Thank you
--
Full question
https://stackoverflow.com/questions/3591...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #css #python27 #jinja2
#avk47
ACCEPTED ANSWER
Score 22
You used "{% %}" which wants to get a tag like if, endif etc. If you just want to execute a piece of python code, like your ternary expression, you should use double braces like so
{{ 'row-story-published' if  person.storyPublished  else ' ' }}
ANSWER 2
Score 2
Template language is different than Python, so has different syntax. You cannot use Python's idiomatic syntax in templates.
<tr class="row-person {% if  person.storyPublished %} row-story-published {% endif %}" >