What's the difference between {% tag variable%} and {{variable}}

What's the difference between {% tag  variable%} and {{variable}}

In Django templates, {% tag variable %} and {{ variable }} are two different types of syntax used for different purposes.

The {% tag variable %} syntax is used for template tags, which are used to perform certain actions in the template such as controlling flow, iterating over data, including templates, etc. The tag is enclosed in {% %} and takes an argument or arguments, which can be variables or literal strings. For example, {% if condition %} ... {% endif %} is a tag that checks if a certain condition is true and executes the code inside the if block if it is.

The {{ variable }} syntax is used to output the value of a variable or expression to the template. It is enclosed in {{ }} and simply outputs the value of the variable or expression. For example, {{ name }} will output the value of the variable "name".

In summary, {% tag variable %} is used for control flow and logic, while {{ variable }} is used for outputting data.

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章