【问题标题】:Invalid block tag: 'bootstrap_icon', expected 'elif', 'else' or 'endif'无效的块标签:'bootstrap_icon'、预期的 'elif'、'else' 或 'endif'
【发布时间】:2018-02-01 11:33:07
【问题描述】:

我尝试了很多,但无法修复此错误。

  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 %}

我尝试了很多东西,但无法成功。请帮忙。 提前致谢。

【问题讨论】:

    标签: django django-bootstrap3


    【解决方案1】:
    {% 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 %}
    

    【讨论】:

      猜你喜欢
      • 2013-06-20
      • 1970-01-01
      • 2023-03-26
      • 2015-04-19
      • 1970-01-01
      • 1970-01-01
      • 2015-09-16
      • 2015-07-08
      • 2013-06-10
      相关资源
      最近更新 更多