1
Good evening, I’m doing the tutorial of Django’s documentation and I came across this code:
{% if latest_question_list %}
<ul>
{% for question in latest_question_list %}
<li><a href="/polls/{{ question.id }}/">{{ question.question_text }}</a></li>
{% endfor %}
</ul>
{% else %}
<p>No polls are available.</p>
{% endif %}
I know that in previous versions we used %s instead of . format or f string, but those {%-- %} I didn’t understand the utility, can someone please explain to me?
These are the template tags of Django and within it you can accomplish several things being one of them, create conditions as in the code of your question to render a certain HTML snippet just if the condition is true.
– JeanExtreme002
Ah, it’s a fancy Django tag then?
– João Paulo Blume
I can’t say that this form of template is unique to Django but yes, this is a template where you insert something to accomplish something in Django. I believe that the template form of the Flask framework for example is the same, although they can do different things.
– JeanExtreme002
That’s not python, that’s html. Just because Django is a python-based framework does not mean that everything related to its development will be in python. Django makes our life a lot easier by giving this "pythonica" approach in various scenarios, but there is no way to extend all python functionality to all components of a website (mainly when we talk about front-end) and also make it suitable for the most diverse scenarios that such a framework proposes.
– Murilo Sitonio