I'm building a site where registered users can upload files. Those files are then served via Apache. Only users who are logged in should be able to access those files.
I have read this page but it seems that people would have to log in twice to access both the site and the media, each time using a different type of login box.
Is there a way around this or is there some other way to limit access to static media served by Apache using the Django authentication database?
I'm using mod_python.
EDIT: How I ended up solving this after reading Van Gale's answer and this:
During development, as long as you have DEBUG set to TRUE and you're using the staticfiles app, you can serve up static files using Django's development server. You don't even need to run the collecstatic command.
Media files are typically user or admin uploadable files. Normally you will want MEDIA_ROOT and STATIC_ROOT to be separate directories. Keep in mind that STATIC_ROOT is where the management command collectstatic will place all the static files it finds.
The usual way to do this is to pass back a special header to the web server.
You can do it with nginx using x-accel-redirect as in this Django snippet.
For Apache, it should be pretty similar using the mod_xsendfile module (discussion and examples on Django users mailing list).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With