1.视图函数
def temp_tags(request):
books = BookInfo.objects.all()
print(books)
return render(request,'booktest/temp_tags.html',{'books':books})
2.模板
模板标签
{% for book in books %}
{% if book.id <= 2 %}
- {{forloop.counter}}--{{book.btitle}}
{% elif book.id <= 5 %}
- {{forloop.counter}}--{{book.btitle}}
{% else %}
- {{forloop.counter}}--{{book.btitle}}
{% endif %}
{% endfor %}
3.url
url(r'^temp_tags$', views.temp_tags),
4.效果