0

``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.`

1

2 Answers 2

0

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!
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for your help i tried on the browser i have this
“C:\Users\New\Documents\mywebsite\mywebsite\media\hotels\images\ht7_t0Oq6SF.jpg” does not exist
So it must have been deleted or removed. You will need to restore the image or update your code to use a different file.
0

use MEDIA_URL for the image:

<img src="{{MEDIA_URL}}{{ m.card_img }}">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.