How to serve media files for Django website
I have a Django website set up on cPanel that is working fine - pages are served on my domain
Any images etc uploaded through Django's admin are saved to a directory I created at
. That's good, but I'm not sure how to serve those images. For example, an image at
should be visible if I visit
in a browser. At the moment it's a 404. How do I serve those images as part of my domain, that's otherwise serving a Django/python app?
www.example.org
Any images etc uploaded through Django's admin are saved to a directory I created at
~/example-org-media/
. That's good, but I'm not sure how to serve those images. For example, an image at
~/example-org-media/hello.jpg
should be visible if I visit
www.example.org/media/hello.jpg
in a browser. At the moment it's a 404. How do I serve those images as part of my domain, that's otherwise serving a Django/python app?
-
I suppose the files don't even have to be in that folder - I could put them anywhere. So the question is: Given the site is a python site served with passenger_wsgi.py, how do I also serve a folder full of images etc? 0 -
In the end I gave up on doing it that way, and instead set up a new Subdomain media.example.org
for serving the media files, from a directory at~/media.example.org/
. I then put this in my Django settings file:MEDIA_ROOT = "/home/USERNAME/media.example.org/" MEDIA_URL = "https://media.example.org/"
I added a .htaccess file in that directory containing this:Header set Access-Control-Allow-Origin "https://www.example.org"
0 -
I'm glad you were able to come up with a good workaround. cPanel support is very limited on the help we can provide for these type of applications, as outlined in the top of the documentation here: How to Install a Python WSGI Application | cPanel & WHM Documentation but I'm glad you found something that works for you! 0 -
you can use: whitenoise ( serve its own static files locally ) or Amazon S3 - Azure Storage
- Dropbox
- Google Cloud Storage
0
Please sign in to leave a comment.
Comments
4 comments