How to add images in the project Django

Question:

My logo doesn’t work in Django project:enter image description here
Code bellow:

index.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Главная</title>
    {% load static %}
<img src="{% static 'media/logo.svg' %}" alt="My logo">
</head>
<body>

</body>
<footer>
 
</footer>
</html>

settings.py:

STATIC_URL = 'static/'

The structure of project:
enter image description here

When i try yo open yje console it takes: Failed to load resource: the server responded with a status of 404 (Not Found)
Logo is in a static/media/logo.svg

Asked By: Proger228

||

Answers:

The static folder should be at the same level as your templates’ folder, and inside the static folder create a new folder for your images you can name the folder anything, save your image inside the folder,

Make sure that Django’s STATICFILES_DIRS setting is correctly configured in your settings file. It should contain the path to your static folder.

or make sure you run collect static management command to copy the files to your Static_root folder

Answered By: Waled Ahmad
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.