2011-09-17 4 views
1

私はDjangoテンプレートを持っています。私はif文で構文エラーがあると思います。 `私は基本的に本は(これはリストである)でない場合、値は、次に、その下に全力を尽くす持っている場合、say-何かをやろうとしているDjangoテンプレート(リストあり)

<head> 
<link rel="stylesheet" type="text/css" href="/static/css/styles.css" /> 
<Meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
</head> 
<body> 
<h1>Testing the class page</h1> 

<div id = "bookResults"> 
<ul> 
{% if books %} 
    {% for book in books %} 
     <li> 
      <div class="bookDisplay"> 
       <div> 
        <text class= "text" id = "bookTitle">{{ book.title|safe }}</text><br/> 
        <text class= "text" id= "bookAuthor">by {{ book.author|safe }}</text><br/> 
        <text class = "test" id = "bookDetails"> 
         ISBN: {{ book.isbn|safe }} 
         Bookstore Price: {{ book.price }} 

        </text><br/> 
        <img src= "{{ book.imageURL }}" class = "bookImage" /> 
       </div> 
      </div> 
     </li> 
    {% endfor %} 
{% else %} 
    <h2>Sorry, no books or classes were found- can you try searching again?"</h2> 
{% endif %} 
</ul> 
</div> 

</body> 

</html>` 

- 私はすでに試した{{場合の本|長さ> 0}}だが役に立たない。

これが動作するにはどうしたらよいですか?

ありがとうございました

+0

どのようなエラーが表示されますか? –

+0

ビューに 'book'がどのように表示されているか教えてください。 –

答えて

8

このコードに問題はありません。

<ul> 
{% for book in books %} 
    <li>...</li> 
{% empty %} 
    <h2>Sorry, no books</h2> 
{% endfor %} 
</ul> 

正しく動作しない場合、間違ったコンテキストをテンプレートに渡しています。

関連する問題