Answer the question
In order to leave comments, you need to log in
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=False
it, 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/'
'django.template.context_processors.media'
Answer the question
In order to leave comments, you need to log in
if
change web settings. server is not allowedthen, 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.
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
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
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.
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 questionAsk a Question
731 491 924 answers to any question