A
A
alexse2016-03-03 19:49:54
Django
alexse, 2016-03-03 19:49:54

How to make a filefield image appear on the site?

Please tell me, I can not upload a photo from the admin panel.
It does not appear in the template.
Registered in the settings:

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

and in urls.py:
if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

The picture is displayed only in the admin panel itself when you click on the link.
Here is my model:
class Book(models.Model):
    image = models.FileField(blank = True, null=True)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2016-03-04
@aleksse

<img src="{{ book.image.url }}" >

R
Roman Kitaev, 2016-03-03
@deliro

There is an ImageField for this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question