Actually, I don't know how to access jsonfield data in the template. I tried something like this
实际上,我不知道如何访问模板中的jsonfield数据。我试过这样的事
{% for key in place.places_to_visit %}
{{ key }}:{{ value }}
{% endfor %}
But it is showing all json data that I have added including {} and " " and also same for Arrayfield of characters I also want to add an image in that jsonfield, how to do that? Does that image need to be media directory and then I should include its path? Or some other ways to do that? It is also showing error as follows
但是它显示了我添加的所有json数据,包括{}和“”,同样对于字符的Arrayfield我也想在jsonfield中添加图像,怎么做?该图像是否需要是媒体目录,然后我应该包含它的路径?或者其他一些方法呢?它还显示如下错误
"[05/Sep/2017 23:03:00] "GET /ontheway/1/ HTTP/1.1" 200 4238"
jsonfield data of places_to visit is
place_to访问的jsonfield数据是
"Places to visit": [
{
"name" : "some name",
"overview" : " some data",
"iamge": "image path"
}
{
"name" : "some name",
"Overview": " some data",
"image": "image path"
}
]
Thank you in advance
先谢谢你
1 个解决方案
#1
0
you can try to use items
:
你可以尝试使用物品:
{% for data in place.places_to_visit %}
{% for key, value in data.items %}
{% if key == 'image' %}
<img src="{{ value }}">
{% else %}
<div> {{ key }}:{{ value }} </div>
{% endif %}
{% endfor %}
{% endfor %}
#1
0
you can try to use items
:
你可以尝试使用物品:
{% for data in place.places_to_visit %}
{% for key, value in data.items %}
{% if key == 'image' %}
<img src="{{ value }}">
{% else %}
<div> {{ key }}:{{ value }} </div>
{% endif %}
{% endfor %}
{% endfor %}