3

Hello I am trying to display an image from media/images

On my html I have this code: index.html

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

{% block metablock %}
<title>CBV - Index</title>
{% endblock metablock %}

{% block bodyblock %}
<div class="container-fluid">
    <h1>Hello {{word}}</h1>
    <img src="/media/images/bobcatminer.jpg" alt="bobcat">
</div>
{% endblock bodyblock %}

on settings.py I have this for media

MEDIA_ROOT = Path.joinpath(BASE_DIR,'media')
MEDIA_URL = '/media/'

I do not know what is going wrong, please help. Thanks beforehand.

1 Answers1

2

Add MEDIA_ROOT in your project's url and app url. Like this :-

In your app's urls (at the end) :-

]

urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

In your project's url (at the end) :-

] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Lars
  • 1,234
  • 1
  • 8
  • 31