在django的HTML中结合python的少量语法
1.python语句都写在{% 。。。%}里
2.if
{% if book.price == 9 %}
光哥优秀
{% elif book.price > 9 %}
光哥有钱
{% else %}
光哥不优秀
{% endif %}
# ==,>左右各一个空格,之后我从服务器端把某本book的记录传过来,用book的书名来调用书的各个属性
3.ifequal / ifnotequal
{% ifequal v1 v2 %}
any statement
{% endifequal %}
#如果v1 == v2两个变量值相等,这执行语句,和 if v1 == v2基本相同
3.for
{% for i in books %} 蕾姆 {% empty %} 当前没有书 {% endfor %}
#books是服务器端传来的一个book表,这个表里有多少本书就打印多少个蕾姆
4.注释
{% comment %}
any statement
{% endcomment %}
#不会显示的注释
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>home</title>
</head>
<body>
{% if name == 9 %}
999
{% endif %}
<br/>
{% for i in books %}
蕾姆
{% endfor %}
</body>
</html>