Как ограничить данные в html с помощью шаблона django? - PullRequest
0 голосов
/ 10 июля 2020

Я использую bootstrap карусель, и я использую шаблон для итерации данных, но мне нужно сразу два данных, поэтому я хотел сделать следующее: если данные превышают 2, я не хочу ничего отображать после этого, может кто-нибудь сказать мне, как сделать это.

<section id="latest-trip">
  <div class="container">
    <div class="row col-md-12">
      <!-- Latest trip left part(carousel part) Start -->
      <div id="treaking-list" class="col-md-7 ml-4">
        <div
          id="carouselExampleIndicators-three"
          class="carousel slide"
          data-ride="carousel"
        >
          <ol class="carousel-indicators">
            <li
              data-target="#carouselExampleIndicators-three"
              data-slide-to="0"
              class="active"
            ></li>
            <li
              data-target="#carouselExampleIndicators-three"
              data-slide-to="1"
            ></li>
            <li
              data-target="#carouselExampleIndicators-three"
              data-slide-to="2"
            ></li>
          </ol>
          <div class="carousel-inner">
            {% for tour in tours %}
            <div class="carousel-item {% if tour.id == 1 %} active {% endif %}">
              <div class="row">
                {% for tour in tours %}
                <div class="treaking col-md-6">
                  <img
                    src="{{tour.image}}"
                    alt="Real Adventure Nepal - {{tour.tour_name}}"
                    title="{{tour.tour_name}}"
                  />
                  <div class="treaking-head">
                    <h3>{{tour.tour_name}}</h3>
                    <p>
                      {{tour.description}}
                    </p>
                  </div>
                </div>
                {% endfor %}
              </div>
            </div>
            {% endfor %}
          </div>
        </div>
      </div>
      <!-- Latest trip left part(carousel part) End -->

      <!-- Latest trip right part(Description part) Start -->
      <div class="col-md-4 ml-5 title">
        <h2 class="treaking-title">Latest Trips</h2>
        <span class="right-styled-para">Explore the unexplored world</span>
        <p class="treaking-description">
          Lorem ipsum dolor sit amet consectetur adipiscing elitsed do eiusmod
          tempor incididunt utlabore et dolore magna aliqua. Utenim ad minim
          veniam quiso.
        </p>
        <button type="button" class="btn btn-primary join-us">
          <a href="treks.html">Join us now</a>
        </button>
      </div>
      <!-- Latest trip right part(Description part) End -->
    </div>
  </div>
</section>

В настоящее время происходит то, что данные уменьшаются, и то же самое происходит в карусели: введите описание изображения здесь

1 Ответ

0 голосов
/ 10 июля 2020

<section id="latest-trip">
  <div class="container">
    <div class="row col-md-12">
      <!-- Latest trip left part(carousel part) Start -->
      <div id="treaking-list" class="col-md-7 ml-4">
        <div
          id="carouselExampleIndicators-three"
          class="carousel slide"
          data-ride="carousel"
        >
          <ol class="carousel-indicators">
            <li
              data-target="#carouselExampleIndicators-three"
              data-slide-to="0"
              class="active"
            ></li>
            <li
              data-target="#carouselExampleIndicators-three"
              data-slide-to="1"
            ></li>
            <li
              data-target="#carouselExampleIndicators-three"
              data-slide-to="2"
            ></li>
          </ol>
          <div class="carousel-inner">
            {% for tour in tours[:2] %}
            <div class="carousel-item {% if tour.id == 1 %} active {% endif %}">
              <div class="row">
                {% for tour in tours %}
                <div class="treaking col-md-6">
                  <img
                    src="{{tour.image}}"
                    alt="Real Adventure Nepal - {{tour.tour_name}}"
                    title="{{tour.tour_name}}"
                  />
                  <div class="treaking-head">
                    <h3>{{tour.tour_name}}</h3>
                    <p>
                      {{tour.description}}
                    </p>
                  </div>
                </div>
                {% endfor %}
              </div>
            </div>
            {% endfor %}
          </div>
        </div>
      </div>
      <!-- Latest trip left part(carousel part) End -->

      <!-- Latest trip right part(Description part) Start -->
      <div class="col-md-4 ml-5 title">
        <h2 class="treaking-title">Latest Trips</h2>
        <span class="right-styled-para">Explore the unexplored world</span>
        <p class="treaking-description">
          Lorem ipsum dolor sit amet consectetur adipiscing elitsed do eiusmod
          tempor incididunt utlabore et dolore magna aliqua. Utenim ad minim
          veniam quiso.
        </p>
        <button type="button" class="btn btn-primary join-us">
          <a href="treks.html">Join us now</a>
        </button>
      </div>
      <!-- Latest trip right part(Description part) End -->
    </div>
  </div>
</section>

Добавление [: 2] после обхода разрешит эту проблему. См. Мой ответ выше.

...