1

As I state in the title, when I set DEBUG = False in my project's settings file, the files from my media directory (the one the user uploads) don't display. The files from my static directory (the CSS and JavaScript files) load properly.

I looked at this answer, but I don't understand the prerequisites to get this to work. I am testing this on my local machine, where I only have Django and PostgreSQL installed. I don't have any Apache servers running, as far as I'm aware. I want to deploy my app on Amazon AWS, so I'd like to try out how it will look in production there before I deploy it to Amazon AWS.

Here are the relevant parts of my settings.py file:

DEBUG = False
ALLOWED_HOSTS = ['*']
STATIC_URL = '/static/'
MEDIA_ROOT = os.path.join(BASE_DIR,'media')
MEDIA_URL = '/media/'
STATICFILES_DIRS = [
   BASE_DIR / "static",
   '/var/www/static/',
]
Eternal_Ether
  • 67
  • 1
  • 10

1 Answers1

0

Willem Van Onsem is right on the media files. Since the static file is OK, for the workaround, you can add this line to your urls.py in the folder containing settings.py:

from django.conf.urls.static import static
from django.conf import settings

urlpatterns+=static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Adi Putra
  • 35
  • 8