有没有一种方法可以将Django模型对象的单独实例插入不同的容器,而无需通过模板中的for循环?

时间:2019-01-09 01:33:16

标签: python html django django-models

我创建了一个简单的Project模型,其中仅包含标题和摘要字段。我想将此模型的唯一实例放入不同的容器中,因为我对CSS的了解还不足以创建一个灵活的可迭代容器。除了为对象的每个实例声明唯一的上下文变量之外,还可以在模板中执行此操作吗?

我在这里放置了一个for循环,以显示将其放置在何处。我是否需要制作四个唯一的上下文词典,每个词典都有自己的唯一循环?

<section class="box features">
    <h2 class="major"><span>Project Portfolio</span></h2>
    <div>
        <div class="row">
            <div class="col-3 col-6-medium col-12-small">

                <!-- Feature -->
                <section class="box feature">
                    <a href="#" class="image featured"><img src="images/pic01.jpg" alt="" /></a>
                    <h3><a href="#">A Subheading</a></h3>
                    <p>
                        Phasellus quam turpis, feugiat sit amet ornare in, a hendrerit in lectus dolore. Praesent semper mod quis eget sed etiam eu ante risus.
                    </p>
                </section>

            </div>
            <div class="col-3 col-6-medium col-12-small">

                <!-- Feature -->
                <section class="box feature">
                    <a href="#" class="image featured"><img src="images/pic02.jpg" alt="" /></a>
                    <h3><a href="#">Another Subheading</a></h3> {% for project in projects %}
                    <p>{{ project.summary }}</p>
                    {% endfor %}
                </section>

            </div>
            <div class="col-3 col-6-medium col-12-small">

0 个答案:

没有答案
相关问题