【发布时间】:2019-02-25 14:46:56
【问题描述】:
我将如何解析它以将商店地址 id 和标题从 api 加载到选择选项值?
到目前为止我已经尝试过什么
<select>
{% for store in stores.store_address %}
<option value="{{ store.store_address.id}}">{{ store.store_address.title}}</option>
{% endfor %}
</select>
获取数据的代码
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
stores = requests.get('https://api.myjson.com/bins/16tdlw').json()
context['stores'] = stores
return context
网址:https://api.myjson.com/bins/16tdlw(json 数据)
模板:
<select>
{% for store in stores.store_address %}
<option value="{{ store.store_address.id}}">{{ store.store_address.title}}</option>
{% endfor %}
</select>
【问题讨论】:
标签: python json django api parsing