0

My website was working fine in both development and production, until I tried to add a google analytics tag to the website which I did incorrectly at first (accidentally put it outside of the head element). After doing this, my site started throwing the above 404 error for every media file it tried to load in production, even though the media files are all in the location that the site seems to be trying to access. The site also works perfectly fine in development with the exact same setup.

Here is the full error I am receiving for every media file on my site:

media_file.ext
Failed to load resource: the server responded with a status of 404 (Not Found)

Below are the relevant parts of my settings.py:

BASE_DIR = Path(__file__).resolve().parent.parent

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

and in my urls.py of my project I have included:

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

I tried both putting the google analytics tag in the head element, which did not work, and then taking the google analytics tag out, which also did not work. I have also tried re-adding the media files to my database by changing the images associated with each django object, which also did not work.

quent
  • 1
  • 1

1 Answers1

0

I set debug = False in settings.py and the website is working again as expected. It seems like I will need to configure Apache to serve the files with debug = True as outlined in the accepted answer to Django media files not showing with Debug = False on production - Django 1.10

quent
  • 1
  • 1