代码1,使用if判断大小
views.py文件:
from django.shortcuts import render
def index(request):
context = {
“age”:17
}
return render(request,‘index.html’,context=context)
index.html文件:
你是未成年人不可以进入网吧
{% elif age == 18 %}你已经18岁了可以进入网吧了
{% else %}你已经是成年人了,需要承担家庭的责任
{% endif %}代码2 if in:
views.py文件:
from django.shortcuts import render
def index(request):
context = {
“heros”:[
“关羽”,
“赵云”
]
}
return render(request,‘index.html’,context=context)
index.html文件:
项羽待命
{% else %}项羽下线了
{% endif %}