V
V
Vova Putsyk2016-04-27 19:48:18
Django
Vova Putsyk, 2016-04-27 19:48:18

How to make images work in django?

Images from the database are not displayed, but images are added through the admin panel. I've tried everything, nothing helps. And static files are loaded. Contents of files:
models.py

image = models.ImageField("Картинка", upload_to="static/img/posts/",  blank=True, null=True)

.html
<img alt="{{ post.title }}" src="/{{ post.image.url }}">

urls.py (Main)
if settings.DEBUG:
    urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Kitaev, 2016-04-27
@deliro

Remove slash in src

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question