在 Django 中围绕 bootstrap html 标签封闭 For 循环

Enclosing For Loop in Django around bootstrap html tags

我对 Django 上的 Python 很陌生。我喜欢将我的 Bootstrap HTML 标签包裹在 Django For..Loop 句柄周围,这样我就可以从列中呈现的数据库中获得我的详细信息。但是,从我所做的事情来看,这并没有发生。第二列实际上搞砸了。这些列应该并排站立。

注意 如果它只有 bootstrap 个标签,它会按照预期的方式呈现得很好。

这里是乱七八糟的图解

下面是我的 Python Django 代码:

templates/app/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 应用程序与 Bootstrap3 集成,但我不知道哪里出了问题。

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

循环结束,没有将所有 <div></div> 匹配。将其从

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

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