0

Django對Python來說是如此的新鮮。我喜歡在Django中包裝我的引導HTML標籤For..Loop處理這樣我從列中呈現的數據庫中獲得我的詳細信息。但是,這並不是從我所做的事情中發生的。第二列實際上搞砸了。這些列設想並排站立。圍繞引導html標籤在Django中的循環使用

注意,如果它的唯一引導標籤,它呈現很好的方式,它假設。

這裏是一塌糊塗的繪畫視圖

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包/寶石整合我的Django應用程序與Bootstrap3,我不知道我做錯了。

回答

2

我認爲問題在嵌套div元素和endfor

循環結束時沒有全部匹配<div></div>。從

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

將其下調一個等級至

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

Wowwwww,你不會相信我做了差不多2個小時檢查通過。我的想法一定不是總結我做得很好。非常感謝。我無法感謝你。 –