【问题标题】:Django favourite/compare featureDjango 最喜欢/比较功能
【发布时间】:2017-12-17 11:52:35
【问题描述】:

只是想知道是否可以使用 Sessions 在我的 Django 应用程序上创建两个产品的快速比较视图。我正在列出待售商品,并希望用户能够“喜欢”多个商品,然后有一个新视图来比较所选产品。有什么想法吗?

谢谢

【问题讨论】:

    标签: python django python-3.x web django-sessions


    【解决方案1】:

    当然,只需将列表产品分配给会话变量即可。

    然后将产品列表分配给模板,它可能看起来像这样:

    <table>
    <tr>
        <td></td>
        {% for product in products %}
        <th>{{ product.title }}</th>
        {% endfor %}
    </tr>
    <tr>
        <th>Feature 1</th>
        {% for product in products %}
        <td>{{ product.feature1 }}</td>
        {% endfor %}
    </tr>
    <tr>
        <th>Feature 2</th>
        {% for product in products %}
        <td>{{ product.feature2 }}</td>
        {% endfor %}
    </tr>
    </table>
    

    【讨论】:

    • 谢谢,看起来不错,你有 CBV 看起来如何的例子吗?
    猜你喜欢
    • 2010-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-26
    • 2020-10-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多