Python Forum

Full Version: display local images on django website
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am using python Django framework.
Image is not displaying when I run the development server.
This is the code, everything else working fine but image is just showing as thumbnail.

<img src="C:\Users\mp88_\OneDrive\Desktop\albumLogos\B0097RFAMU.jpg">

<h1>{{ album.album_title }}</h1>
<h3>{{ album.artist }}</h3>

<ul>
  {% for song in album.song_set.all %}
    <li>{{ song.song_title }} - {{ song.file_type }}</li>
  {% endfor %}
</ul>
would anyone know why?
You can not use a local path like this in Django.
Look at Managing static files (e.g. images, JavaScript, CSS)
Point 1 and 2 should have been added automatically.
Check eg settings.py that there is:
STATIC_URL = '/static/'
Now make a folders static/images in your app folder.
Place image in images folder eg img_girl.jpg.
Then a html file in templates could look like this.
<!-- templates/image.html -->
{% extends 'base.html' %}

{% block content %}
{% load static %}
<!DOCTYPE html>
<html>
<body>
  <h2>HTML Image</h2>    
  <!-- The Django way -->
  <img src="{% static "images/img_girl.jpg" %}"  alt="Girl in a jacket" width="500" height="600">

  <!-- Direct path to image -->
  <img src="../static/images/img_girl.jpg" alt="Girl in a jacket" width="500" height="600">  
</body>
</html>
{% endblock %}
that helped solve my issue.
thank you.