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
#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


Messages In This Thread
display local images on django website - by mp3909 - Mar-30-2020, 05:43 PM
RE: display local images on django website - by snippsat - Mar-30-2020, 11:50 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Fetching Images from DB in Django Dexty 2 1,777 Mar-15-2024, 08:43 AM
Last Post: firn100
  Django images will not load pythonpaul32 3 2,883 Jul-20-2023, 10:30 AM
Last Post: Gaurav_Kumar
  please help me with my django website? MetsxxFan01 0 1,547 May-05-2022, 11:38 PM
Last Post: MetsxxFan01
  Cant Download Images from Unsplash Website firaki12345 1 2,343 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,385 Jun-30-2019, 12:21 AM
Last Post: scidam
  How to get this function using Django in building a website? py2exe 0 2,481 Jul-25-2018, 09:56 AM
Last Post: py2exe
  Django packages for website with paid user accounts jmarchini 2 3,585 Jan-08-2018, 09:10 AM
Last Post: SarbjitGrewal
  Display google recpatcha at the end of the form django-allauth app prithvi 2 4,171 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,349 Jul-23-2017, 06:14 AM
Last Post: amit
  How to integrate a python algorithm in a Django website daekch 2 5,348 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