变量相关{{ }}
逻辑相关{%%}
传参
'''str int 对象 列表 字典都可以传'''
def t_test(request):
name = 'kun'
list = ['张','王','李']
dict = {'name1':27,"name2":18}
# 也可以传对象
p1 = Person('娃娃',1) # 对象
return render(request,'t_test.html',{'name1':name,'list':list,'dict':dict,'person1':p1)
循环
当前循环. | 作用 |
---|---|
forloop.counter | 循环计次 |
forloop.last | 最后一个循环 |
{% for user in user_list %} <!--循环头-->
<tr>
{{ forloop.counter }} <!--循环计次-->
<td>{{ user.id }}</td>
<td>{{ user.names }}</td>
</tr>
{% endfor %} <!--循环尾-->
判断 if
{% if 判断条件 %}
执行语句
{% else %}
执行语句
{% endif %}
判断包含 if..in
{% if id in id_lis %}
执行语句
{% endif %}