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.

 

 

 

参考文章

评论可见,请评论后查看内容,谢谢!!!评论后请刷新页面。