A
A
Alexander2018-10-04 18:09:06
Django
Alexander, 2018-10-04 18:09:06

How to display an ImageField in a view?

Can't find an error. Images not showing, not found
settings.py

DEBUG = True
...
MEDIA_ROOT = os.path.join(BASE_DIR, 'articles')
MEDIA_URL = '/media/'

models.py
class Tutorials(models.Model):
    image = models.ImageField(verbose_name='Лого статьи', upload_to='articles/')

template.html
{% for article in articles %}
    <div class="row">
        <img src="{{ article.image.url}}" >
    </div>
    {% endfor %}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2018-10-04
@cashncarry

The problem was in urls.py , forgot + static(..)

from django.conf.urls.static import static

urlpatterns = [
 # ...
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question