#32304: Django adds spurious "/" prefix to settings.STATIC_URL="http://server/"
-------------------------------------+------------------------------------
Reporter: Adam Hooper | Owner: nobody
Type: Bug | Status: new
Component: contrib.staticfiles | Version: 3.1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+------------------------------------
Comment (by Florian Apolloner):
Uff, yes that is certainly a bug. I think your proposed fix is okay; but
I'd also remove the usage of the `URLValidator` completely. Maybe:
{{{
diff --git a/django/conf/__init__.py b/django/conf/__init__.py
index 23fee7d5b7..fc36b64d05 100644
--- a/django/conf/__init__.py
+++ b/django/conf/__init__.py
@@ -16,7 +16,6 @@ from pathlib import Path
import django
from django.conf import global_settings
from django.core.exceptions import ImproperlyConfigured, ValidationError
-from django.core.validators import URLValidator
from django.utils.deprecation import RemovedInDjango40Warning
from django.utils.functional import LazyObject, empty
@@ -132,14 +131,8 @@ class LazySettings(LazyObject):
Useful when the app is being served at a subpath and manually
prefixing
subpath to STATIC_URL and MEDIA_URL in settings is inconvenient.
"""
- # Don't apply prefix to valid URLs.
- try:
- URLValidator()(value)
- return value
- except (ValidationError, AttributeError):
- pass
- # Don't apply prefix to absolute paths.
- if value.startswith('/'):
+ # Don't apply prefix to absolute paths and URLs.
+ if value.startswith(('/', 'http://', 'https://')):
return value
from django.urls import get_script_prefix
return '%s%s' % (get_script_prefix(), value)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32304#comment:6>
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/068.c2ef1b7d5f2c0e4ca213c27ccbe39ba7%40djangoproject.com.