1.视图函数
def temp_tags(request):
books = BookInfo.objects.all()
print(books)
return render(request,'booktest/temp_tags.html',{'books':books})
2.模板
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>模板标签</title>
<style>
.red{
background-color:red
}
.yellow{
background-color:yellow
}
.green{
background-color:green
}
</style>
</head>
<body>
<ul>
{% for book in books %}
{% if book.id <= 2 %}
<li class="red">{{forloop.counter}}--{{book.btitle}}</li>
{% elif book.id <= 5 %}
<li class="yellow">{{forloop.counter}}--{{book.btitle}}</li>
{% else %}
<li class="green">{{forloop.counter}}--{{book.btitle}}</li>
{% endif %}
{% endfor %}
</ul>
</body>
</html>
3.url
url(r'^temp_tags$', views.temp_tags),
4.效果