Impossible to make an image appear in Django

Hello,

I’ve been learning Python for a few weeks now and I started a project with Django but I’m going crazy trying to make a simple picture appear on a HTML page using Django… I don’t understand why the won’t show up on the HTML page of my Django app.
The only thing I get is the “alt” name and nothing else.

The console shows the following errors:
Not Found: /media/test.jpg
“GET /media/test.jpg HTTP/1.1” 404 2233

I have checked the BASE_DIR and the folder media is correcty written. I have even changed the BASE_DIR to a CUSTOM_BASE_DIR to put the path manually and it is still the same…

Can you please help me and explainto me why is it doesn’t work and why is it so hard to make a simple picture appear ?

Thanks in advance :frowning:

We’ll be happy to try and help, but we’re going to need to see what you’re trying to do.

Let’s start with the model containing the field you’re trying to display, the view trying to display it, and the template being used to render that part of the page.

We’ll also need to see your settings relative to your MEDIA files.

Side note: When posting code or templates here, enclose the code between lines of three backtick - ` characters. This means that you’ll have a line of ```, then your code (or template), then another line of ```.

Thanks for your quick reply, it is my first time posting so thanks for all the advices too.

I tried with an empty html template. I have nothing but :

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
    <img src="/application/media/test.jpg" alt="test2">
    
</body>
</html>

I don’t get what you mean by settings relative to my MEDIA file. I just created a folder called media and put 1 image called “test” inside.

You’ll want to read How to manage static files (e.g. images, JavaScript, CSS) | Django documentation | Django to understand how to work with static files in your project.

Side note: You used apostrophe - ' instead of the backtick - ` to fence off your code. I fixed that for you here.

1 Like

Thanks and thanks again ! I found the problem with your link and it’s working perfectly now !