Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • 1
    I suppose you're right, I'll just use if/else. Just addicted to ternary I guess. Commented Jun 24, 2010 at 13:14
  • 18
    I would like to see ternary support, too. Commented Nov 20, 2012 at 18:39
  • 60
    I tend to disagree with Daniel. I recently converted a django template to a simple javascript template: {% if data_complete %}{{ data }}{% else %}{{ something_else }}{% endif %} became <%= data_complete ? data : something_else %> ... the second is so much more compact and elegant. It would be nice if there was an equivalent in django. Commented Apr 27, 2013 at 15:51
  • 15
    "why would you" ... well, to do something in 30 sec instead of 10mn, for instance. Django templating isn't so developer-friendly, it's not always a good thing to have to do stuff in the view instead of the template. Commented Aug 5, 2018 at 0:53
  • because if else is damn pain in the eye to see and write and it goes of the screen <a class="btn {% if prospect.has_been_called %}btn-warning{% else %}btn-success{% endif %} d-block" We want ternary, just like we wanted wheels 10000 years ago Commented Apr 28, 2024 at 4:13