Home > OS >  Image print issue in HTML using Django
Image print issue in HTML using Django

Time:10-17

I have recently started working with Python Django. I created a home page and it worked fine. But now I created another html template product.html and followed the same steps but the images weren't loading even though both the html files were in the same directory. I tried printing image product-1.jpeg in home page and it worked but in the other html page it isn't working. All the CSS are working fine. I don't know what am I doing wrong here.

product.html

{% load static %}

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="shortcut icon" type="image/png" href='{% static "images/favicon.ico" %}'/>
</head>
<body>
    <p style="color:red;">Hello</p>
    <img src="static/images/product-1.jpeg" alt="Product 1"/>
</body>
</html>

Terminal Response

[17/Oct/2021 00:42:21] "GET /Product/ HTTP/1.1" 200 416
Not Found: /Product/static/images/product-1.jpeg
[17/Oct/2021 00:42:21] "GET /Product/static/images/product-1.jpeg HTTP/1.1" 404 2899
[17/Oct/2021 00:42:22] "GET /static/images/favicon.ico HTTP/1.1" 200 15406
[17/Oct/2021 00:49:31] "GET /Product/ HTTP/1.1" 200 442

Website Display Web Page View

Let me know, if I need to upload other codes (urls.py, views.py, settings.py, etc. Btw home.html was working fine)

CodePudding user response:

For the img tag use the below format for src field

src="{% static '/images/product-1.jpeg' %}"
  • Related