【问题标题】:I would like to pass an array in django我想在 django 中传递一个数组
【发布时间】:2021-08-25 02:39:30
【问题描述】:

我想在 django 中传递一个数组

{% include '/blocks/block-products-carousel.html' with
        groups= [
            {title: 'All', active: true},
            {title: 'Power Tools', active: false},
            {title: 'Hand Tools', active: false},
            {title: 'Plumbing', active: false},
        ],

【问题讨论】:

标签: arrays django django-templates


【解决方案1】:

你可以在视图代码中创建数组(列表)并像这样将它传递给上下文

 def view(request)
     groups_list = [
        {title: 'All', active: true},
        {title: 'Power Tools', active: false},
        {title: 'Hand Tools', active: false},
        {title: 'Plumbing', active: false},
    ]
     render (request,"template.html",{"groups_list":groups_list})

然后在你的模板中

 {% include '/blocks/block-products-carousel.html' with groups=groups_list %}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-22
    • 2016-08-16
    • 1970-01-01
    • 2019-12-26
    • 2017-12-22
    • 1970-01-01
    相关资源
    最近更新 更多