booktest-16模板过滤器 date length default

1.V

def temp_filter(request):
    books = BookInfo.objects.all()
    print(books)
    return render(request,'booktest/temp_filter.html',{'books':books})

2.T




    
    模板过滤器
    


    
    {% for book in books %} {% if book.id <= 2 %}
  • {{book.btitle|length}}--{{book.bpub_date|date:'Y年-m月-d日'}}
  • {% else %}
  • {{book.btitle}}--{{book.bpub_date|date:'Y年-m月-d日'}}
  • {% endif %} {% endfor %}
{{content|default:'hello'}}

3.url

url(r'^temp_filter$', views.temp_filter),

4.效果

booktest-16模板过滤器 date length default_第1张图片

你可能感兴趣的:(python)