#Python #Shorts
Django doesn't only let us pass in variables from the backend code to the template but it also allows us to render certain elements on the page based on some conditions.
Just think of it as if you were able to use the if/elif/else statements inside the HTML files. And with Django, you actually can!
To do that, use the single curly braces with two percent % symbols inside them, and put your if statement in between the % signs. For example, {% if now.year == 2020 %}
And the follow it by the HTML elements that you want to display if this condition is true.
{% if now.year == 2020 %}
After that, either add an elif condition or an else statement using the same logic, and at the end "terminate" your conditional logic with {% endif %} to let Django know that you're done here.
-------------------------------------------------------------------------------------
Links:
Blog: https://evgenyurubkov.com
Twitter: / evgenyurubkov
Instagram: / evgenyurubkov
Youtube: / @codevev
Смотрите видео How to Use If Elif Else Conditions in Django Template (HTML) - Python Web Development онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь codevev 30 Июнь 2021, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 1,050 раз и оно понравилось 26 людям.