WHITENOISE_AUTOREFRESH = False does not prefix static urls correctly
See original GitHub issueWhitenoise 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: https://github.com/evansd/whitenoise/blob/7161a8f45a4e4204047a846c31cbb6cc90326ed9/whitenoise/base.py#L80-L83
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.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (4 by maintainers)
Confirmed fixed with Whitenoise 0.5.2 Thanks, and sorry for the testing delay.
@ajslater I think #259 might solve your problem, but hard to tell without being able to reproduce.