詹戈。无法从ImageField加载图片

2024-03-29 10:47:39 发布

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

我正在尝试从模板中的ImageField上载图片,但它没有显示。代码和截图将更好地解释。你知道吗

你知道吗设置.py你知道吗

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

你知道吗型号.py你知道吗

image = models.ImageField()

你知道吗视图.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})

你知道吗线程.html你知道吗

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

{% block content %}
<div class="op_post">
    <img src="{{op_post.image.url}}">
</div>
{% endblock content %}

你知道吗线程.html浏览器中的源

enter image description here


Tags: pyimageboardidurlhtmlstaticroot