1.V
def temp_filter(request):
books = BookInfo.objects.all()
print(books)
return render(request,'booktest/temp_filter.html',{'books':books})
2.T
<!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">{{book.btitle|length}}--{{book.bpub_date|date:'Y年-m月-d日'}}</li>
{% else %}
<li class="green">{{book.btitle}}--{{book.bpub_date|date:'Y年-m月-d日'}}</li>
{% endif %}
{% endfor %}
</ul>
{{content|default:'hello'}}
</body>
</html>
3.url
url(r'^temp_filter$', views.temp_filter),
4.效果