从模板中的视图中获取不带unicode值的可迭代JSON

2024-03-29 09:43:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我创建了一个python(2.7)字典,其结构如下:

cntr_rgns = {'country_1':[region1, region2, region3], 'country_2':[region1, region2] ..}

我将其作为以下内容传递给我的上下文词典:

ctx['regions'] = cntr_rgns

我想要的是在我的模板中显示值

在我的模板视图中,我做到了:

{% if regions %}
    {% for region in regions.items %}
        <option value={{ region }}>{{ region }}</option>
    {% endfor %}
{% endif %}

但我再次得到了unicode值:

(u'Canada',[u'somethong',u'something',u'something',u…)

我怎样才能得到一个可迭代的JSON或其他东西


Tags: 模板字典结构countryregionsomething词典option