Serving Media files in cPanel Shared Hosting for Django Web App

I am not able to display media files on Cpanel shared hosting Django web app. I receive a Error 404 URL Not Found whenever I try to access the media file.

I have specified + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) in my urls.py file.

This error only occurs whenever DEBUG = False. I am using whitenoise to serve the static files without any issue it is only the media directory that causes the 404 web error.

settings.py

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

I am using Python v3.8.6, Django=2.1 and CPanel Shared Hosting via NameCheap.

I know it's recommended to have a webserver to store and serve media files in Production Environment but I am unable to edit the Apache httpd.conf file as mentioned in the Django documentation.

Back to Top