1

I have a web app that takes uploaded images and displays it to the user after registration. I have the media and static files separated in respective folders. When I run the app with debug as True, the images are served up to be displayed, but when debug is off, the images don't show. I have tried having the media folder under the static folder and running collectstatic and the images show. But when new images are uploaded, they are not served until the collectstatic is run again. Do I have to keep running collectstatic or there is better to have these folders separated and the images still show??

Praise
  • 43
  • 6

1 Answers1

2

Yes, these folders should be separated. In Debug mode runserver serves these data for you:

During development, if you use django.contrib.staticfiles, this will be done automatically by runserver when DEBUG is set to True (see django.contrib.staticfiles.views.serve()).

This method is grossly inefficient and probably insecure, so it is unsuitable for production.

In production (DEBUG=False) you need to use more suitable tools, for instance, gunicorn in combination with nginx. Check out this guide to understand how to properly set up your workflow in production.

funnydman
  • 9,083
  • 4
  • 40
  • 55
  • Hey, thanks. Thing is I have read that documentation but it says nothing about media files, just statics files. Could you explain more on how using these tools would help? – Praise Jan 10 '20 at 15:23
  • @Praise `runserver` isn't desired for production usage, and in case of `DEBUG=False` won't server static(and media) files for you, but still, you could use `--insecure` option but there is strong advice not to do this. These tools do the job perfectly, `gunicorn` is just a production-ready replacement for `runserver` and `nginx` is used as a proxy. – funnydman Jan 10 '20 at 18:14