Django的。无法从ImageField加载图片

时间:2016-07-29 08:42:01

标签: python django

我正在尝试从模板中的ImageField上传图片,但不会显示。代码和屏幕截图将更好地解释。

settings.py

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
MEDIA_URL = '/media/'
MEDIA_ROOT = '/media/veracrypt1/django/pycaba/pycaba/media/'

models.py

image = models.ImageField()

views.py

def thread(request, boardname, thread_id):
    board = boardname
    thread = thread_id
    op_post = get_object_or_404(Posts, board=board, id=thread_id)
    return render(request, 'board/thread.html', {'op_post':op_post})

thread.html

{% extends 'board/base.html' %}

{% block content %}
<div class="op_post">
    <img src="{{op_post.image.url}}">
</div>
{% endblock content %}
浏览器中的

thread.html源

enter image description here

1 个答案:

答案 0 :(得分:0)

你使用的Django版本是什么?您是否在网址模式中加入了static file urls