首页 > 解决方案 > 显示动态数据;第一行是 6 列,另一行是 col-3 col-3

问题描述

我想显示来自管理员的动态数据发布,第一行在 6 列中,其他是 col-3 col-3,我还想在同一页面上发布不同的数据,但来自同一模型的其他部分。请任何人都可以解决这个问题。

**models.py**
class Homepost(models.Model):
    name = models.CharField(max_length=120)
    title = models.CharField(max_length=120)
    description = models.TextField()

    def __str__(self):
        return self.name

**views.py**

 def home(request):
    Homeposts = Homepost.objects.all()
    context = {
        'Homeposts': Homeposts
    }
    return render(request, 'home/index.html', context)


**index.html**  
 <section id="text-wraper">
         <div class="container">
          {% for Homepost in Homeposts %}
            <div class="row">
               <div class="col-md-6">
               <div class="card">
                    <div class="card-body">
                        <h5 class="card-title">{{Homepost.name}}</h5>
                        <h5 class="card-title">{{Homepost.title}}</h5>
                        <p class="card-text">{{Homepost.description}}</p>
                        <a href="#" class="btn btn-primary">Go 
                        somewhere</a>
                    </div>
                    </div>
               </div> <!-- end col 6 -->
               <div class="col-md-3">
               <div class="card">
                    <div class="card-body">
                        <h5 class="card-title">Card title</h5>
                        <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
                        <a href="#" class="btn btn-primary">Go somewhere</a>
                    </div>
                    </div>
               </div> <!-- end col 3 -->
            </div>
             {% endfor %}
         </div>     
  </section>

标签: django-modelsdjango-viewsdjango-templates

解决方案


推荐阅读