行视图中的Django图像



我在Django中创建了一个模型,可以将图片上传到管理站点,稍后它将显示在主页中。

*.html文件

<!-- templates/home.html -->
<h1>Django Image Uploading</h1>
<ul>
{% for post in object_list %}
<h2>{{ post.title }}</h2>
<img src="{{ post.cover.url}}" alt="{{ post.title }}">
{% endfor %}
</ul>

如何在行视图中显示所有图片?而不是列?(我想建立的图片库页面(

正如您提到的bootstrap-4作为标签之一,下面是使用bootstrap的方法;

<div class="container">
<div class="row"> <!-- all the divs placed inside this div will be placed in a row instead of column -->
<div class="col-sm">
One of three columns
</div>
<div class="col-sm">
One of three columns
</div>
<div class="col-sm">
One of three columns
</div>
</div>
</div>

类别为rowdiv内的所有divs将水平放置在一行中。

欲了解更多信息,请点击此处;https://getbootstrap.com/docs/5.0/layout/grid/#row-列

最新更新