0

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?

3
  • Can you provide some sort of concrete error message? Commented Mar 26, 2022 at 15:38
  • It have no error but image not display Commented Mar 26, 2022 at 15:39
  • 1
    Try like this {% static 'media/images/iot_logo.png' %} Commented Mar 26, 2022 at 15:40

2 Answers 2

1

Use the built-in static tag

{% load static %}

<img class="rounded mx-auto d-block" width="25%" src="{% static 'media/images/iot_logo.png' %}">
Sign up to request clarification or add additional context in comments.

Comments

0

Seems like path you given here in src is incorrect,

correct your path and image will be visible to you.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.