我尝试了很多,但无法修复此错误。
TemplateSyntaxError at /myrestaurants/restaurants/1/
Invalid block tag: 'bootstrap_icon', expected 'elif', 'else' or 'endif'
Request Method: GET
Request URL: http://127.0.0.1:8000/myrestaurants/restaurants/1/
Django Version: 1.8.7
Exception Type: TemplateSyntaxError
Exception Value:
Invalid block tag: 'bootstrap_icon', expected 'elif', 'else' or 'endif'
Exception Location: /usr/lib/python2.7/dist-packages/django/template/base.py in invalid_block_tag, line 395
Python Executable: /usr/bin/python
Python Version: 2.7.12
Python Path:
['/home/vaibhav/Desktop/projects/myrecommendations',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/home/vaibhav/.local/lib/python2.7/site-packages',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages/gtk-2.0']
Server time: Thu, 1 Feb 2018 16:53:44 +0000
实际上我想要显示一个表格,其中第一列应该显示客户给出的星号。这是我的代码部分,我得到错误: -
{% if restaurant.restaurantreview_set.all != 0 %}
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Rating</th>
<th>Comment</th>
<th>User</th>
<th>Date</th>
</tr>
</thead>
<tbody>
{% for review in restaurant.restaurantreview_set.all %}
<tr>
<td>{% if review.rating == 1%}{% bootstrap_icon "star" %}
{% elif review.rating == 2%}{% bootstrap_icon "star" %}{% bootstrap_icon "star" %}
{% elif review.rating == 3%}{% bootstrap_icon "star" %}{% bootstrap_icon "star" %}{% bootstrap_icon "star" %}
{% elif review.rating == 4%}{% bootstrap_icon "star" %}{% bootstrap_icon "star" %}{% bootstrap_icon "star" %}{% bootstrap_icon "star" %}
{% elif review.rating == 5%}{% bootstrap_icon "star" %}{% bootstrap_icon "star" %}{% bootstrap_icon "star" %}{% bootstrap_icon "star" %}{% bootstrap_icon "star" %}{% endif %}</td>
<td>{{ review.comment }}</td>
<td>{{ review.user }}</td>
<td>{{ review.date }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p>Please post the review.</p>
{% endif %}
我尝试了许多事情,但无法成功。请帮忙。 提前谢谢。
答案 0 :(得分:0)
{% load bootstrap3 %} -- add this line at the top of your layouts file
{% if restaurant.restaurantreview_set.all != 0 %}
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Rating</th>
<th>Comment</th>
<th>User</th>
<th>Date</th>
</tr>
</thead>
<tbody>
{% for review in restaurant.restaurantreview_set.all %}
<tr>
<td>{% if review.rating == 1%}{% bootstrap_icon "star" %}
{% elif review.rating == 2%}{% bootstrap_icon "star" %}{% bootstrap_icon "star" %}
{% elif review.rating == 3%}{% bootstrap_icon "star" %}{% bootstrap_icon "star" %}{% bootstrap_icon "star" %}
{% elif review.rating == 4%}{% bootstrap_icon "star" %}{% bootstrap_icon "star" %}{% bootstrap_icon "star" %}{% bootstrap_icon "star" %}
{% elif review.rating == 5%}{% bootstrap_icon "star" %}{% bootstrap_icon "star" %}{% bootstrap_icon "star" %}{% bootstrap_icon "star" %}{% bootstrap_icon "star" %}{% endif %}</td>
<td>{{ review.comment }}</td>
<td>{{ review.user }}</td>
<td>{{ review.date }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p>Please post the review.</p>
{% endif %}