Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WHITENOISE_AUTOREFRESH = False does not prefix static urls correctly #258

Closed
ajslater opened this issue Jul 8, 2020 · 5 comments
Closed

Comments

@ajslater
Copy link

ajslater commented Jul 8, 2020

Whitenoise breaks subpath behavior in production (but works in debug) with Django 3.1.
Django 3.1 lets you serve django from subpaths more easily by correctly prefixing static urls (e.g. https://my.big.site/mysmallapp/)

In Django 3.1 static urls are prefixed if there is a url path prefix specified by settings (FORCE_SCRIPT_NAME) or, more likely, from the webserver. This prefix is often delivered by the script_name wsgi variable or the root_path asgi variable and stored in django.urls.base._prefixes.

The issue seems to occur here:

if self.autorefresh:
static_file = self.find_file(path)
else:
static_file = self.files.get(path)

The find_file() function ends up with a code path that correctly prefixes the static file, while the files.get() code path does not.

Workaround right now is just to manually set WHITENOISE_AUTOREFRESH = True in production. The side effects from this are not terrible.
But the expected behavior in Django 3.1 would be for this to work when AUTOREFRESH is False.

Django 3.1 is expected to release August 4, 2020.

django.urls.get_script_prefix() will supply the prefix, but its more likely that the path should come from some existing django static method.

@evansd
Copy link
Owner

evansd commented Jul 9, 2020

Hi, thanks for this exemplary bug report!

I'll add the 3.1 beta to the test matrix and get this fixed.

@evansd
Copy link
Owner

evansd commented Jul 24, 2020

@ajslater I'm struggling to reproduce this. Can you post some example code which demonstrates the problem?

@evansd
Copy link
Owner

evansd commented Jul 24, 2020

Ah, I think maybe I understand. Django 3.1 adds new behaviour whereby you can use a relative path in STATIC_URL and have that automatically prefixed with the value of get_script_prefix(). And the problem is that WhiteNoise doesn't support this new behaviour, rather than that anything that used to work is now broken with 3.1. Is that correct?

@evansd
Copy link
Owner

evansd commented Jul 29, 2020

@ajslater I think #259 might solve your problem, but hard to tell without being able to reproduce.

@ajslater
Copy link
Author

Confirmed fixed with Whitenoise 0.5.2
Thanks, and sorry for the testing delay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants