django如何在JSONfield中添加图像? [英] django how to add image in JSONfield?
本文介绍了django如何在JSONfield中添加图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
目录结构我想在JSONfield中添加图像.这是我的json数据:
directory structure I want to add an image in JSONfield. Here is my json data:`
{"name": "some name", "image": "static 'ontheway/images/m1.jpg'", "overview": "some data"},
{"name": "some name", "image": "static 'ontheway/images/a1.jpg", "overview": "some data"}]
在模板中,我做了这样的事情:
In the template I have done something like this :
{% 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 %}
未显示图像,而是显示了其路径. 我已将图像存储在静态文件中,是否需要将图像存储在媒体中? 预先谢谢你
The images are not getting displayed instead its path is displayed. I have stored images in static files, do I need to store images in media? Thank you in advance
推荐答案
您应将图像存储在static
文件夹中,然后像这样显示它们:
You should store your images in static
folder and then show them like this:
{% load static %}
<img src="{% static value %}">
这篇关于django如何在JSONfield中添加图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文