-
Notifications
You must be signed in to change notification settings - Fork 152
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_STATIC_PREFIX still required if django app deployed on subpath #271
Comments
Your reading of the docs is correct so this does sound like a bug, but I'm struggling to understand what might be causing it. Can you post a minimal reproducing example somewhere? |
I recently ran into something similar in https://github.com/ome/omero-web-docker. That's definitely not a minimal example, but I'm pretty sure it used to work, so if I get time I might be able to pin down the version where it broke. |
#259 is the problematic PR in my case, 5.1.0 works, 5.2.0 doesn't. I'm using Django 1.11 with something like
The related issue #258 says
I'm not familiar with Django 3, but could it be that if settings.FORCE_SCRIPT_NAME:
script_prefix = settings.FORCE_SCRIPT_NAME.rstrip("/")
else:
script_prefix = get_script_prefix().rstrip("/")
... |
I had a similar issue. I've not hosted django on apache before with mod_wsgi but figured I would try it out. I had django mounted under '/d':
Which meant my static files weren't being served. I updated my config to
(yes FORCE_SCRIPT_NAME is commented out) I checked and |
I had a similar issue which I solved by setting |
I believe this is still an issue, I've been experiencing incorrect pathing from static assets with whitenoise which I spent a bit of time debugging in TandoorRecipes/recipes#1878 and https://code.djangoproject.com/ticket/34028. The root cause seems to be that recent Django versions cache the prefix and setting values based on their first access. Normally first access is a HTTP request so SCRIPT_NAME would be set on it and all is well... However, whitenoise attempts to access the configured STATIC_URL during middleware initialization, as you can see here:
Since this is during initialization and outside a HTTP request context, SCRIPT_NAME is absent and therefore the Django prefix gets incorrectly returned as '/' (i.e. STATIC_URL gets set to '/static/' and then remains that way). This causes all the asset URIs to be wrong when a real request comes in with SCRIPT_NAME header set. In theory setting FORCE_SCRIPT_NAME should address this by short-circuiting SCRIPT_NAME and ensuring the Django prefix is set correct on whitenoise middleware initialization, but in my testing I didn't see that behavior. The prefix only gets set on the first HTTP request, so until then even with FORCE_SCRIPT_NAME set the prefix is still '/' according to Django - and that's what whitenoise sees. Note sure if thats a Django issue or if whitenoise needs to add an explicit check for FORCE_SCRIPT_NAME. |
This issue still exists. |
The docs for WHITENOISE_STATIC_PREFIX currently say
I understand this to mean if in my settings.py I have
WHITENOISE_STATIC_PREFIX
will automatically be/static/
However, this is not the case and i still need to explicitly set in my settings.py
otherwise static files will not work.
Is this a bug, or am I misunderstanding something in the docs? I did see #164 which seems similar but different enough (no mention of
FORCE_SCRIPT_NAME
) where it explicitly mentions needing to do this, but that issue is from 2017 and seems to contradict the above documentation.am using
The text was updated successfully, but these errors were encountered: