Search code examples
pythondjangohttp-status-code-404web-deployment

I have tried many solutions but image is not showing when I run server. ;( on django


{% extends "base.html" %}

{% load static %}

{% block content %}
<h1>{{ project.title }}</h1>
<div class="row">
    <div class="col-md-8">
        **<img class="img-fluid" src="{{project.image}}">**
    </div> 
    <div class="col-md-4">
        <h5>About the project:</h5>
        <p>{{ project.description }}</p>
        <br>
        <h5>Technology used:</h5>
        <p>{{ project.technology_used }}</p>
    </div>
</div>
{% endblock %}

I got this error:

[20/Feb/2021 21:49:31] "GET /project/1 HTTP/1.1" 200 1427
Not Found: /project/static/img/1-webgrow.jpg

and the static folder is in project directory.

This is the view function:

def details(request, pk):
    project = Project.objects.get(pk=pk)
    context = {
        'project': project
    }
    return render(request, 'details.html', context)

please help


Solution

  • you forgot to use .url in your code It should be like this

    <img class="img-fluid" src="{{project.image.url}}">
    

    and also, the images of models are not stored in statics folder, their in media root