Python Forum
display local images on django website
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
display local images on django website
#1
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?
Reply
#2
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 %}
Reply
#3
that helped solve my issue.
thank you.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Fetching Images from DB in Django Dexty 2 1,622 Mar-15-2024, 08:43 AM
Last Post: firn100
  Django images will not load pythonpaul32 3 2,375 Jul-20-2023, 10:30 AM
Last Post: Gaurav_Kumar
  please help me with my django website? MetsxxFan01 0 1,485 May-05-2022, 11:38 PM
Last Post: MetsxxFan01
  Cant Download Images from Unsplash Website firaki12345 1 2,257 Feb-08-2021, 04:15 PM
Last Post: buran
  Django: How to automatically substitute a variable in the admin page at Django 1.11? m0ntecr1st0 3 3,245 Jun-30-2019, 12:21 AM
Last Post: scidam
  How to get this function using Django in building a website? py2exe 0 2,415 Jul-25-2018, 09:56 AM
Last Post: py2exe
  Django packages for website with paid user accounts jmarchini 2 3,503 Jan-08-2018, 09:10 AM
Last Post: SarbjitGrewal
  Display google recpatcha at the end of the form django-allauth app prithvi 2 4,094 Aug-08-2017, 09:19 PM
Last Post: prithvi
  read text file using python and display its output to html using django amit 0 18,261 Jul-23-2017, 06:14 AM
Last Post: amit
  How to integrate a python algorithm in a Django website daekch 2 5,283 Mar-21-2017, 10:58 AM
Last Post: Jeanne

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020