T
T
tank0072019-10-21 22:54:31
Django
tank007, 2019-10-21 22:54:31

How to display images in Django production?

Good afternoon.
Uploaded a site written in django 2.2.6 to reg.ru.
As soon as I translated DEBAG=Falseit, the pictures stopped showing, while the static is visible.
Code from settings.py:

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

I also made the following entry in context_processors:
'django.template.context_processors.media'
Pictures are loaded into the specified folder, but are not displayed on the pages.
Those. reg.ru support suggested converting all pictures to static, but I think this is a so-so idea.
I also found a similar topic https://toster.ru/q/219424, which talks about changes in web settings. servers, though those. support replied that changing the web settings. server is not possible.
Can you please tell me how to display images on a site with disabled debugging?

Answer the question

In order to leave comments, you need to log in

6 answer(s)
S
szelga, 2019-10-22
@tank007

if

change web settings. server is not allowed
then, probably, the only way is to collect the statics in the directory /static/s/, and the downloaded files - respectively in /static/m/(choose the names to your liking and in accordance with the existing web server settings). or change hoster/switch to VDS.

A
Antonio Solo, 2019-10-22
@solotony

where is the media folder? it needs to be available to the webserver (i.e. be inside the document root)
i just link it there from the django project

F
Filin Filin, 2019-10-21
@geekfil

I haven't worked with django for a long time, but if I'm not mistaken, you need a library.
Here is all the info whitenoise.evans.io/en/stable

V
Vampre, 2019-10-22
@Vampre

Site on VDS? Try to paste the link directly into the browser and see what the server writes in the logs.
You can also check if the user under which the server is running has rights to the folder with pictures.

A
Alibaba2018, 2019-10-22
@Alibaba2018

Have you tried python manage.py collectstatic?

S
Sergey Nizhny Novgorod, 2019-10-22
@Terras

1) Are the roots written to media pictures in the database?
2) How are pictures displayed in the template?
3) Is it VPS or Shared Hosting?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question