Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "{%" do in HTML?

I've added Django messages to my app using the official documentation. In it it says to add something like this to my template:

{% if messages %}
<ul class="messages">
    {% for message in messages %}
    <li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
    {% endfor %}
</ul>
{% endif %}

I have no idea what the percentage signs do, they're not actual HTML right?

like image 610
Amon Avatar asked Dec 12 '16 05:12

Amon


People also ask

What does {% %} indicate in HTML?

file inclusion (or transclusion)

What does {% %} mean in Django?

{% %} and {{ }} are part of Django templating language. They are used to pass the variables from views to template. {% %} is basically used when you have an expression and are called tags while {{ }} is used to simply access the variable.


1 Answers

It's a template engine syntax use in html pages, django compile it when you render a view html with a context variable and return a basic html response.

In your case your message will be your context variable and django engine compile it like :

if message is not None then inner part html is visible.

Doc. Link: https://docs.djangoproject.com/en/1.7/topics/templates/

like image 139
GrvTyagi Avatar answered Oct 11 '22 22:10

GrvTyagi