P
P
Pan Propan2016-02-27 00:48:08
Django
Pan Propan, 2016-02-27 00:48:08

How to insert MEDIA_URL in Django template?

Can you please tell me how to insert a link to a file in the template? If I go directly through the browser using the link 127.0.0.1:8000/media/images/img.jpg then the image opens.
Tried it didn't work

<img src="{{ MEDIA_URL }}/images/img.jpg" alt="..." class="img-circle profile_img">

statics included in the template
{% load staticfiles %}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sim3x, 2016-02-27
@mgis

static - content related to the framework and what is written on it
https://docs.djangoproject.com/en/1.9/howto/static...

{% load staticfiles %}
<img src="{% static "my_app/myexample.jpg" %}" alt="My image"/>

media - content that was generated during the application. It could be generated by users, admins, etc.
Links to media files are made even easier
{{ mymodel.my_image_field.url }}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question