Reputation: 365
I am very new to django and working on it.. I visited a html file and dont know the difference between {{}} and {% %} in html files used as here
{% load static %}
Thanks a lot
Upvotes: 10
Views: 9816
Reputation: 29
{% %} for IF ELSE CONDITIONS
and FOR LOOP etc
{{ }} for veriables that rendered from view function also used in FOR LOOP veriables like
`enter code here`
{% for obj in qs%}
{{ obj.veriable_name }}
{% endfor %}
Upvotes: 1
Reputation: 41
There are three things in the template in Django
First is template variable and the second thing is template tag and third and last is template filter
so we write a template variable is {{}}
and write a template tag is {% %}
third and last is template filter {{variable |filter:arg}}
Upvotes: 4
Reputation: 3371
You can use
{% %}
For sentences such as if
and for
or to call tags such as load
, static
, etc.
{{ }}
To render variables in the template.
Read More about it at Django Docs
Upvotes: 16
Reputation: 21
I'm new too for Django, so if i'm wrong, please someone correct me. The difference between they are:
{{variable}}
is used to use a variables. When the template encounters a variable, it evaluates that variable and replaces it with the result.
You also can use filters {{variable|filter}}
like this:
{{name|length}}
in this case you will use a variable "name" and return the length of that variable.
{%tag%}
could use for loops or logic, or load external information into the template to be used by later variables. You can create block tags to help extend other html files parts. Also you can create custom tags.
A good place to see how to do it: https://www.codementor.io/hiteshgarg14/creating-custom-template-tags-in-django-application-58wvmqm5f
Tags like loops and block, need to be closed.
Upvotes: 2