user572575
user572575

Reputation: 1049

Django cannot show image

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 class="rounded mx-auto d-block" 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?

Upvotes: 0

Views: 42

Answers (2)

Adil Mohak
Adil Mohak

Reputation: 375

Use the built-in static tag

{% load static %}

<img class="rounded mx-auto d-block" width="25%" src="{% static 'media/images/iot_logo.png' %}">

Upvotes: 1

Krishna510
Krishna510

Reputation: 11

Seems like path you given here in src is incorrect,

correct your path and image will be visible to you.

Upvotes: 0

Related Questions