我正在尝试从模板中的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源