1
1
12LiCaNtRoP122021-06-07 18:31:18
Django
12LiCaNtRoP12, 2021-06-07 18:31:18

How to include an image in HTML?

I’m learning Django, while studying, I came across the display of images on the site, but there is a problem: when you run the html file, everything works, the image appears, and if you call this html file using render (), then it simply is not displayed.

{%extends 'mapp/found.html'%}

{%block title%}
{{game.name}} - подробно
{%endblock%}
{%block body%}
<pre class='detailed'>
{{game.name}} - {{game.cost}} ₽
{{style}}
</pre>
<p class='main-text'>
{{game.text}}
</p>
<img src='C:\Games\mysite\images\output\2021\06\07\заду.png' alt='Картинка'>
{%endblock%}

Do not pay attention if the code seems garbage, all the names were invented on a whim, having nothing meaningful, except for what is in curly brackets, because this is just a test of how to make everything work. The link to the image is absolute, because before that I tried to fix it dohrel times, but to no avail, so in order to better understand and make sure that the problem is not in the link itself, I left it absolute. Everything from this code works, but not the image, instead of it there is my alternative inscription. I read about it, but all the problems are related only to the fact that errors come out when the template is displayed, but I don’t have this either, there are options, because of what this could be ??

Answer the question

In order to leave comments, you need to log in

2 answer(s)
1
12LiCaNtRoP12, 2021-06-07
@12LiCaNtRoP12

That's it, I found the answer, the fact is that in the tag in the src attribute I simply wrote the model field that determines the address to the image, but I had to put .url after that. In short, I did everything.

Y
Yupiter7575, 2021-06-07
@yupiter7575

Because you are running this on a server. Create a folder called static, upload images to it and use special. functions, refer to them (these functions are easily searched for by a search engine)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question