DJBarnes / django-adminlte2-pdq

A Django app that takes all of the work out of making a beautiful and functional web application pretty darn quickly (PDQ) using the AdminLTE2 theme.
MIT License
6 stars 0 forks source link

Login Required / Strict causes issues with Media URL #19

Closed DJBarnes closed 2 years ago

DJBarnes commented 2 years ago

If you are trying to serve Media files with manage.py runserver, it is impossible to get the media files to serve properly when Login Required and/or Strict Policy is turned on. This is because there is no way to add the media URL to the Whitelists.

Should maybe just add some additional logic to the Middleware to look at the media URL and count anything that starts with that URL as valid. Use a regex to ensure URLs start with the media URL.

Not sure if static files could also be affected?

DJBarnes commented 2 years ago

Fixed. Now skips checking for permissions / login required for all requests that start with a URL that matches the MEDIA_URL setting. One caveat is that if the MEDIA_URL is left with the default value, it will not allow media files through. This is because the default is effectively '/', the root of the site, and more than likely all actual media will be in a separate URL such as '/media/' anyway. Allowing it to work with the MEDIA_URL setting set to the default value would essentially invalidate all protection since every single URL in the site will start with '/'. Hence why it still blocks if the MEDIA_URL is the default and not set to something else.