V
V
Vlad2422019-03-27 19:26:42
Django
Vlad242, 2019-03-27 19:26:42

How to add an image to a django template?

Do I do it like this or do I need it like this: UPD: I have all the pictures in my media folder
<img src="{{ MEDIA_URL }}media/pig4.jpg"
<img src="{% static 'image.jpg' %}">

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
FulTupFul, 2019-03-27
@FulTupFul

In settings.py:

MEDIA_ROOT = os.path.join(BASE_DIR, "media/")
MEDIA_URL = '/media/'

In urls:
urlpatterns = + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) + static(settings.MEDIA_URL,
                                                                             document_root=settings.MEDIA_ROOT)

Take the picture in the template using model.field.url

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question