围绕bootstrap html标签围绕Django中的循环

时间:2017-03-19 22:48:21

标签: python django python-2.7 django-templates django-bootstrap3

在Django上对Python这么新。我喜欢将我的Bootstrap HTML标签包装在Django For..Loop处理中,以便我从Columns中呈现的数据库中获取我的详细信息。但是,它并没有发生在我所做的事情上。第二栏实际上搞砸了。列被认为是并排站立的。

注意如果只有它自己的引导标签,那么它的呈现方式就会非常好。

以下是混乱的图示

enter image description here

下面是我的Python Django代码:

模板/应用/ home.html做为

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8">
        <title>Mentoring Services</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="Mentoring Services">
        <meta name="keywords" content="">
        <meta name="author" content="Myrioi Solutions">
        <!-- FAVICON -->
        <link rel="shortcut icon" href="images/favicon.ico">
        <link rel="stylesheet" href="static/css/base.css">
        {# Load the tag library #}
        {% load bootstrap3 %}

        {# Load CSS and JavaScript #}
        {% bootstrap_css %}
        {% bootstrap_javascript %}

        {# Display django.contrib.messages as Bootstrap alerts #}
        {% bootstrap_messages %}
    </head>
<body>

<div class="intro" data-stellar-background-ratio="0.55" style="background-position: 50% 50%;">
  <div class="container">
      <div>
          <h4>Get mentored and be successful</h4>
      </div>
      <div class="#">
          <h1 style="transition: none; text-align: inherit; line-height: 62px; border-width: 0px; margin: 14px 0px 9px; padding: 0px; letter-spacing: 0px; font-size: 55px; color: black">
            Mentoring Directory
          </h1>
          <p class="lead">The most complete solution<br>
             for online mentoring directories
          </p>
     </div>
  </div>
</div>


<div class="home-directory">
            <div class="container">
                <div class="section-head text-center">
                    <h3>Best rated Mentors</h3>
                    <p class="lead">Explore some of our best mentors around your place and connect with them.</p>
                </div>
                <div class="row">
                 {% for item in mentors %}
                    <div class="col-md-4 col-sm-6 col-sm-offset-3 col-md-offset-0">
                        <div class="listing">
                            <div class="listing-img bg-image" data-image-src="{{ item.image }}" style="background: url(&quot;images/home/3.jpg&quot;) center center / cover no-repeat;">
                                <div class="li-overlay">
                                    <div class="li-overlay-inner">
                                        <a href="#" class="mail"></a>
                                        <a href="#" class="menu"></a>
                                        <a href="#" class="link"></a>
                                    </div>
                                </div>
                            </div>
                            <div class="listing-info">
                                <h4 class="li-name"><a href="#">{{ item.first_name }} {{ item.last_name }}</a></h4>
                                <ul class="list-icon">
                                    <li> <i class="pe-7s-map-marker"></i> {{ item.location }}</li>
                                    <li> <i class="pe-7s-call"></i> {{ item.phone_number }}</li>
                                    <li> <i class="pe-7s-mail"></i> <a href="mailto:{{ item.email }}">{{ item.email }}</a> </li>
                                </ul>
                            </div>
                        </div>
                    {% endfor %}
                    </div>
                </div>
            </div>
        </div>
</body>

</html>

view.py

from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render
from django.views import View
from .models import *
from .models import Mentor


# Create your views here.


class HomeView(View):
    # @staticmethod
    def get(self, request, *args, **kwargs):
        mentors = Mentor.objects.all()
        return render(request, "mentoring_application/home.html", {"mentors": mentors})

注意:我正在使用django-bootstrap3 package / gem将我的Django App与Bootstrap3集成,我不知道到底出了什么问题。

1 个答案:

答案 0 :(得分:2)

我认为问题在于div元素和endfor的嵌套。

循环结束时不会将所有<div></div>匹配。从

向下移动一级
        </div>
    {% endfor %}
    </div>
</div>

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