0

I'm trying to find the answer for the name of the question that I posted, but I couldn't seem to find the answer.

I've been looking at several tutorials in Django and they keep on telling me that you should not use the MEDIA_URL and MEDIA_ROOT type of convention when you're at the production level of Django.

But why is that? Is there a specific reason for it?

SihwanLee
  • 129
  • 1
  • 9

1 Answers1

2

There's nothing wrong with those variables in particular. The fact is you never want to serve static files using Django's dev server in production, both because of performance and security issues.

The dev server is very helpful, because it allows you to use nothing but Django to serve static files and media files during development, but it is not a production web server in any way (such as Nginx for example).

The docs are, as always, helpful: https://docs.djangoproject.com/en/3.1/howto/static-files/#serving-uploaded-files-in-development

What applies to static files also applies to media files. For strategies about static files deployment, there's a whole page on the docs too.

Some packages, such as Whitenoise, help when dealing with static files in production, but Whitenoise can't be used for media (user-uploaded) static files (because roughly it discovers static files at start).

Le Minaw
  • 835
  • 7
  • 17
  • Thanks for the answer! – SihwanLee Nov 07 '20 at 06:49
  • Everybody keeps repeating this statement from the docs ("This is not suitable for production use!") but nobody goes into detail explaing why it actually is that way. The performance thingy is a given but the security thing depends, imho, on a buch of factors. It would be nice if it wasn't so black and white. – nuts May 12 '22 at 16:31