skip to Main Content

“Images are rendering from other pages but nit rendering new page

views.py

def hotels(request):
    mhtl = Hotel.objects.all()
    context = {
        'my_rms': mhtl,
    }
    return render(request,'affiliate/hotels.html', context)

type here

models.py
class Hotel(models.Model):
    title = models.CharField(null=True, blank=True, max_length=100)
    price = models.CharField(null=True, blank=True, max_length=100)
    card_img = models.ImageField(null=True, blank=True, upload_to="images/")

    def __str__(self):
        return self.title`

The html page
{% extends ‘affiliate/base.html’ %}

{% load static %}

{% block content %}

<h2>Find your next stay</h2>
<h3>HERE</h3>
<h5>--- WIDGET WIDGET WIDGET WIDGET ---</h5><hr>
<!--CARDS-->
        
        {% for m in my_rms %} 
                                    
                           
                <img src="{{ m.card_img }}">
                
                    <h5>{{m.title}}</h5>
                    <p>${{ m.price }}</p>
                  
                     
           
        {% endfor %}  
    
<hr> 

{% endblock content %}

other datas are rendering except the image and the message from the terminal is:

[28/Mar/2023 10:17:48] "GET /hotels/images/ht7.jpg HTTP/1.1" 404 2991
Not Found: /hotels/images/ht7.jpg

I am trying to find a way to resolve this please

I tried a for lood to retrieve data from a specific model otherdatas are rendering only image is not.`

2

Answers


  1. Looks like the server can’t find the image at that URL. I can suggest you doing the following:

    1. Check if the image file is present in the specified location.
    2. Make sure that the file has read permission, and that the web server is able to access it.
      Try accessing the image file directly from the web browser, using the URL specified in the error message. This will help you identify if the issue is with the image file or with the way it is being accessed from the server.
      Hope that helps!
    Login or Signup to reply.
  2. use MEDIA_URL for the image:

    <img src="{{MEDIA_URL}}{{ m.card_img }}">
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search