Home > OS >  Django cannot show image
Django cannot show image

Time:03-27

I use django in Ubuntu. I set static_url, static_root, media_url and media_root in settings.py like this code.

settings.py

DEBUG = False

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
MEDIA_URL='/media/'
MEDIA_ROOT=os.path.join(BASE_DIR,'static','media')

In index.html I set image like this code.

index.html

<img  width="25%" src="../media/images/iot_logo.png">

After that, I use command django-admin collectstatic and open website but it not show image. How to fix it?

CodePudding user response:

Use the built-in static tag

{% load static %}

<img  width="25%" src="{% static 'media/images/iot_logo.png' %}">

CodePudding user response:

Seems like path you given here in src is incorrect,

correct your path and image will be visible to you.

  • Related