【问题标题】:Using for loops for dispaying values in django template使用 for 循环在 django 模板中显示值
【发布时间】:2017-03-27 15:24:33
【问题描述】:

如果我使用“for 循环”,则 Db 中的所有数据都会垂直显示。为了透明,我写了一个没有 HTML 的示例。第二个代码“my.html”是 HTML 代码。我想将分区(或表格)水平显示。如果我运行 my.html 我有两个垂直显示的分区,我怎样才能将它们水平放置?我想水平显示两个相邻的部门(或表格),并且像 post.prop_one 这样的值必须垂直显示在部门或表格中。

{% for post in posts %}
    {{post.option_one}}
    {{post.option_two}}
{% endfor %}

我的.html

<!-- myprices --> 
        <div id="pricing" class="container-fluid">   
    <div class="text-center">
                <h2>Pricing</h2>
                  <h4>blabla</h4>   
</div> {% for post in posts %}
                <div class="row slideanim-'inline'">
                <div class="col-sm-4 col-xs-12">

                  <div class="panel panel-default text-center">
                    <div class="panel-heading">

                  <h1><a href="">{{ post.offer_option}}</a></h1>
                    </div>
                      <div class="panel-body">
                          <p><strong>20</strong> {{post.prop_one}}</p>
                          <p><strong>20</strong>{{post.prop_two}} </p>
                          <p><strong>20</strong>{{post.prop_three}}</p>
                      </div>
                       <div class="panel-footer">
                        <h3>{{ post.price}}</h3>
                        <h4>{{ post.period}}</h4>
                       </div>
                      <button class="btn btn-lg">Sign Up</button>
                    </div>
                  </div>
                </div>
                  {% endfor %}

【问题讨论】:

  • 将两个表放在另一个表中。或使用bootstrap 类,如"col-sm-4 col-xs-12"
  • 你的问题不清楚。您是要水平显示表格中的项目(即在单个表格行中),还是要水平显示两个相邻的整个表格?
  • 另外,您的示例代码根本不使用表格,所以您的问题更加不清楚。
  • 我编辑了我的帖子。 -furas:正如我在帖子中提到的那样。我已经使用 col-sm-4 和 col-xs-12。 @John Gordon我想要两个divisons或tables在水平方向上彼此相邻显示。像post.prop_one这样的值必须在divisions或table中垂直显示。谢谢

标签: python html mysql django django-templates


【解决方案1】:

你循环整个内容..你想要循环的只是col-sm-4 col-xs-12。 您的“for 循环”和结束标记错误地放置在您的 html 中。 这是一个例子

       <!-- Container (Pricing Section) -->
<div id="pricing" class="container-fluid">
  <div class="text-center">
    <h2>Pricing</h2>
      <h4>blabla</h4>
  </div>

    <div class="row slideanim-'inline'">
        {% for post in posts %}
    <div class="col-sm-4 col-xs-12">


      <div class="panel panel-default text-center">
        <div class="panel-heading">

      <h1><a href="">{{ post.offer_option}}</a></h1>
        </div>
          <div class="panel-body">
              <p><strong>20</strong> {{post.prop_one}}</p>
              <p><strong>20</strong>{{post.prop_two}} </p>
              <p><strong>20</strong>{{post.prop_three}}</p>
          </div>
           <div class="panel-footer">
            <h3>{{ post.price}}</h3>
            <h4>{{ post.period}}</h4>
           </div>
          <button class="btn btn-lg">Sign Up</button>
        </div>

      </div>{% endfor %}
    </div>

【讨论】:

    猜你喜欢
    • 2018-08-11
    • 1970-01-01
    • 2017-09-22
    • 2020-09-21
    • 1970-01-01
    • 2023-02-01
    • 1970-01-01
    • 2018-05-28
    • 2012-07-25
    相关资源
    最近更新 更多