question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WHITENOISE_AUTOREFRESH = False does not prefix static urls correctly

See original GitHub issue

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: 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:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ajslatercommented, Aug 27, 2020

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

0reactions
evansdcommented, Jul 29, 2020

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Django url with prefix - not working correctly - Stack Overflow
I am using Django 1.7 with Mezzanine. URL of my pages has a prefix www.example.com/example. So I use: FORCE_SCRIPT_NAME = '/example'.
Read more >
Dynamic URLs vs. static URLs | Google Search Central Blog
A static URL is one that does not change, so it typically does not contain any URL parameters. It can look like this:...
Read more >
How to mount a Flask app under a URL prefix (or really, any ...
This will make sure the URLs are correctly prefixed with SCRIPT_NAME , if applicable. This is recommended as best practice by the Flask...
Read more >
URL-prefix property - Search Console Help - Google Support
A Search Console property that, as defined, includes the protocol (http or https) and can include a path string when you created the...
Read more >
#25598 (Add support for SCRIPT_NAME in STATIC_URL and ...
When running on sub-path, using SCRIPT_NAME WSGI param, it results in incorrect static URL - it doesn't prepend SCRIPT_NAME prefix. This problem can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found