python - 如何在 Django 中将行调整为列?

标签 python html css django

我在 index.html 中做了一个循环,我在 views.html 中添加了图片,每当我运行代码时,所有的图片都会出现在行中。我希望它出现在列中。我怎么能那样做?

views.py
    def index(request):
    dest1 = Destination()
    dest1.desc = 'Hello, How are you?'
    dest1.img = '01.jpg'

    dest2 = Destination()
    dest2.desc = 'Hello, HOw are you?'
    dest2.img = '02.jpg'

    dests1 = [dest1, dest2]
    return render(request, 'index.html',{'dests1':dests1})

  index.html
    {% static 'images/fulls' as baseUrl %}
    {% static 'images/thumbs' as hiUrl %}
    {% for dest1 in dests1 %}
    <div>
    <a href="{{baseUrl}}/{{dest1.img}}">
        <img src="{{hiUrl}}/{{dest1.img}}" alt="" />
        <h3>{{dest1.desc}}</h3>
    </a>
   </div>
    {%endfor%}

最佳答案

尝试将此添加到您的代码中:

<div class="row">
{% for dest1 in dests1 %}
<div class="col-lg-4">
    <a href="{{baseUrl}}/{{dest1.img}}">
        <img src="{{hiUrl}}/{{dest1.img}}" alt="" />
        <h3>{{dest1.desc}}</h3>
    </a>
</div>
{%endfor%}
   </div>

关于python - 如何在 Django 中将行调整为列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56963622/

相关文章:

python - BigQuerySink 的 bigquery.TableSchema 的 JSON 表架构

javascript - Angular 翻译 HTML 标签

javascript - 2016年如何在排除机器人和爬虫的情况下收集浏览量?

html - 分页后重复表格标题

python - PyCharm/PyQt : How to obtain code completion with dynamically loaded ui files

python - 如何使用 RDFLib 导出 RDF 文件中的图形

css - System.Web.Optimization 捆绑 css js 缓存

html - 编辑 iframe 中元素的 CSS

python - 为 mongoengine 0.9.0 StringField 设置正则表达式模式

javascript - svg 外部对象中的 Canvas 不应用转换