I'm trying to put image on my website with Django framework. But it always gives an error 404. I already tried some recommendations, but it still doesn't work
Here is my settings.py file:
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
STATICFILES_DIRS = [
os.path.join(PROJECT_ROOT, 'static'),
]
STATIC_URL = '/static/'
And here is my HTML file:
{% load static %}
<!DOCTYPE html>
<html>
<img src="{% static 'media/logo2.jpeg' %}" alt="photo" height="100" width="500">
<p>HEllo world</p>
{% block content %}
replace me
{% endblock %}
</html>
I want the web page to display my image. Thanks.
You didn't provide project tree and urls.py. You can follow Django's official documentation. To check click here
You can also try using this code snippet:
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]