#35312: staticurl_urlpatterns incorrectly uses STATIC_URL that prefixed using SCRIPT_NAME -----------------------------------------------+------------------------ Reporter: yudhiwidyatama | Owner: nobody Type: Bug | Status: new Component: contrib.staticfiles | Version: 5.0 Severity: Normal | Keywords: Triage Stage: Unreviewed | Has patch: 0 Needs documentation: 0 | Needs tests: 0 Patch needs improvement: 0 | Easy pickings: 0 UI/UX: 0 | -----------------------------------------------+------------------------ Deploying Django using Gunicorn with SCRIPT_NAME set to '/django', we get the url for static resources are correctly generated with '/django/static/' prefix, but the static url patterns is also prefixed with the '/django/static/'. This is wrong because url patterns will be compared with the PATH_INFO part of the URL without the script_name prefix.
Reproduce step : 1. create a django app with static directory containing image or css files. 2. append static url pattern to site's urls.py by either appending urlpatterns += staticfiles_urlpatterns() or urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) (refer: https://docs.djangoproject.com/en/5.0/howto/static-files/) 3. serve using gunicorn by previously setting SCRIPT_NAME environment variable to /django 4. access the url served by gunicorn (http://localhost:8000/django/<appname>) 5. the application urls are served under /django prefix, the generated static urls also having the /django/static prefix. 6. accessing application url, gunicorn correctly renders pages, but not the static content suggestion : a. change staticfiles_urlpatterns() in contrib/staticfiles/urls.py to check whether the urlpatterns prefix starts with get_script_prefix(), and if so, strip the get_script_prefix() part from prefix b. or change the settings.STATIC_URL in the howto page with expression that strips the SCRIPT_NAME part or get_script_prefix() part. -- Ticket URL: <https://code.djangoproject.com/ticket/35312> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/0107018e46f4200b-7bb91f4d-9e58-41ad-aaf5-283d115cd214-000000%40eu-central-1.amazonses.com.