display local images on django website - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html) +--- Thread: display local images on django website (/thread-25442.html) |
display local images on django website - mp3909 - Mar-30-2020 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? RE: display local images on django website - snippsat - Mar-30-2020 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 %} RE: display local images on django website - mp3909 - Apr-01-2020 that helped solve my issue. thank you. |