首页 > 其他分享 >What's the difference between {% tag variable%} and {{variable}}

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

时间:2023-03-27 19:24:29浏览次数:39  
标签:What used syntax tag template between 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.

 

 

 

标签:What,used,syntax,tag,template,between,variable
From: https://www.cnblogs.com/chucklu/p/17262554.html

相关文章