django-models - 显示动态数据;第一行是 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>
解决方案
推荐阅读
- nginx - 运行 ASP.NET Core Web 应用程序的 Amazon Lightsail - 无法从浏览器访问网站
- angular - Angular bootstrap Carousel-如何在 Angular 组件中移动到 ng-bootstrap carousel 的下一个图像?
- google-apps-script - 无法从其容器中打开包含的 Google Apps 脚本项目
- php - 递归遍历 SimpleXML 对象*其中结构未知*
- vue.js - 我无法使用该州的 formData 在服务器上发布我的文件
- excel - 根据单元格值删除行
- csv - 根据列中的值删除行
- facebook - 通过 Facebook API 提升 Instagram 帖子
- android - Xamarin.Forms:在地图点击时隐藏 ListView?
- c# - Visual Studio 2017 设计器视图不显示控件