{{{
STATIC_URL = "http://minio/static/"
}}}
Django 3.1 will implicitly add "/" to the URL, so my URLs look like
""/http://minio/static/images/app-icons/favicon.ico".
The features and bugs that interact here:
* commit c574bec, adding feature #25598, prepends SCRIPT_NAME to
STATIC_URL when STATIC_URL isn't a URL.
* bug #9202: according to Django, "http://minio/static/" isn't a valid
URL. (It is.)
Top me, the easiest fix is to address #9202....
--
Ticket URL: <https://code.djangoproject.com/ticket/32304>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Old description:
> Here's a piece of settings from a totally reasonable, sensible, okay
> Docker integration-test environment
>
> {{{
> STATIC_URL = "http://minio/static/"
> }}}
>
> Django 3.1 will implicitly add "/" to the URL, so my URLs look like
> ""/http://minio/static/images/app-icons/favicon.ico".
>
> The features and bugs that interact here:
>
> * commit c574bec, adding feature #25598, prepends SCRIPT_NAME to
> STATIC_URL when STATIC_URL isn't a URL.
> * bug #9202: according to Django, "http://minio/static/" isn't a valid
> URL. (It is.)
>
> Top me, the easiest fix is to address #9202....
New description:
Here's a piece of settings from a totally reasonable, sensible, okay
Docker integration-test environment
{{{
STATIC_URL = "http://minio/static/"
}}}
Django 3.1 will implicitly add "/" to the URL, so my URLs look like
""/http://minio/static/images/app-icons/favicon.ico".
The features and bugs that interact here:
* commit c574bec, adding feature #25598, prepends SCRIPT_NAME to
STATIC_URL when STATIC_URL isn't a URL.
* bug #9202 and #25418: according to Django, "http://minio/static/" isn't
a valid URL. (It is.)
Top me, the easiest fix is to address #9202 / #25418....
--
--
Ticket URL: <https://code.djangoproject.com/ticket/32304#comment:1>
Old description:
> Here's a piece of settings from a totally reasonable, sensible, okay
> Docker integration-test environment
>
> {{{
> STATIC_URL = "http://minio/static/"
> }}}
>
> Django 3.1 will implicitly add "/" to the URL, so my URLs look like
> ""/http://minio/static/images/app-icons/favicon.ico".
>
> The features and bugs that interact here:
>
> * commit c574bec, adding feature #25598, prepends SCRIPT_NAME to
> STATIC_URL when STATIC_URL isn't a URL.
> * bug #9202 and #25418: according to Django, "http://minio/static/" isn't
> a valid URL. (It is.)
>
> Top me, the easiest fix is to address #9202 / #25418....
New description:
Here's a piece of settings from a totally reasonable, sensible, okay
Docker integration-test environment
{{{
STATIC_URL = "http://minio/static/"
}}}
Django 3.1 will implicitly add "/" to the URL, so my URLs look like
""/http://minio/static/images/app-icons/favicon.ico".
The features and bugs that interact here:
* commit c574bec, adding feature #25598, prepends SCRIPT_NAME to
STATIC_URL when STATIC_URL isn't a URL.
* bug #9202 and #25418: according to Django, "http://minio/static/" isn't
a valid URL. (It is.)
Top me, the easiest fix is to address #9202 / #25418. Or to make
`STATIC_URL` use some logic that is different from URLValidator.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/32304#comment:2>
Comment (by Adam Hooper):
My workaround was to create a phony URL and point to it in
{{{/etc/hosts}}}.
Yes, really.
https://github.com/CJWorkbench/cjworkbench/commit/6aec10f441f5392bda7df247cddc8828b52a0c84
--
Ticket URL: <https://code.djangoproject.com/ticket/32304#comment:3>
Old description:
> Here's a piece of settings from a totally reasonable, sensible, okay
> Docker integration-test environment
>
> {{{
> STATIC_URL = "http://minio/static/"
> }}}
>
> Django 3.1 will implicitly add "/" to the URL, so my URLs look like
> ""/http://minio/static/images/app-icons/favicon.ico".
>
> The features and bugs that interact here:
>
> * commit c574bec, adding feature #25598, prepends SCRIPT_NAME to
> STATIC_URL when STATIC_URL isn't a URL.
> * bug #9202 and #25418: according to Django, "http://minio/static/" isn't
> a valid URL. (It is.)
>
> Top me, the easiest fix is to address #9202 / #25418. Or to make
> `STATIC_URL` use some logic that is different from URLValidator.
New description:
Here's a piece of settings from a totally reasonable, sensible, okay
Docker integration-test environment
{{{
STATIC_URL = "http://minio/static/"
}}}
Django 3.1 will implicitly add "/" to the URL, so my URLs look like
{{{/http://minio/static/images/app-icons/favicon.ico}}}
The features and bugs that interact here:
* commit c574bec, adding feature #25598, prepends SCRIPT_NAME to
STATIC_URL when STATIC_URL isn't a URL.
* bug #9202 and #25418: according to Django, "http://minio/static/" isn't
a valid URL. (It is.)
Top me, the easiest fix is to address #9202 / #25418. Or to make
`STATIC_URL` use some logic that is different from URLValidator.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/32304#comment:4>
* cc: Florian Apolloner (added)
* component: Core (Other) => contrib.staticfiles
* severity: Normal => Release blocker
* stage: Unreviewed => Accepted
Comment:
Thanks for the report, as a workaround you can set the
[https://docs.djangoproject.com/en/3.1/ref/settings/#force-script-name
FORCE_SCRIPT_NAME] setting to an empty string:
{{{#!python
FORCE_SCRIPT_NAME = ''
}}}
Ticket #9202 was rejected and will not be fixed. I think it should be fine
to add `http://` and `https://` to recognizing absolute paths, e.g.
{{{
diff --git a/django/conf/__init__.py b/django/conf/__init__.py
index 23fee7d5b7..c2ddc942db 100644
--- a/django/conf/__init__.py
+++ b/django/conf/__init__.py
@@ -139,7 +139,7 @@ class LazySettings(LazyObject):
except (ValidationError, AttributeError):
pass
# Don't apply prefix to absolute paths.
- if value.startswith('/'):
+ if value.startswith(('http://', 'https://', '/')):
return value
from django.urls import get_script_prefix
return '%s%s' % (get_script_prefix(), value)
}}}
Florian, What do you think?
--
Ticket URL: <https://code.djangoproject.com/ticket/32304#comment:5>
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>
* owner: nobody => Mariusz Felisiak
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/32304#comment:7>
Comment (by Hasan Ramezani):
Mariusz,
I didn't realize that you assigned the ticket to yourself. I just created
a [https://github.com/django/django/pull/13823 PR] based on Florian
Apolloner proposed patch.
Feel free to close my PR if you have something else in your mind.
Thanks
--
Ticket URL: <https://code.djangoproject.com/ticket/32304#comment:8>
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/13824/ PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/32304#comment:9>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/32304#comment:10>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"e13b71403bd1568abed237858127677144d43d23" e13b7140]:
{{{
#!CommitTicketReference repository=""
revision="e13b71403bd1568abed237858127677144d43d23"
Fixed #32304 -- Fixed prefixing STATIC_URL and MEDIA_URL by SCRIPT_NAME
for absolute URLs with no domain.
Thanks Adam Hooper for the report.
Regression in c574bec0929cd2527268c96a492d25223a9fd576.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32304#comment:11>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"5fdc81d8930b85849a39e550fa54be1cad10d74d" 5fdc81d]:
{{{
#!CommitTicketReference repository=""
revision="5fdc81d8930b85849a39e550fa54be1cad10d74d"
[3.1.x] Fixed #32304 -- Fixed prefixing STATIC_URL and MEDIA_URL by
SCRIPT_NAME for absolute URLs with no domain.
Thanks Adam Hooper for the report.
Regression in c574bec0929cd2527268c96a492d25223a9fd576.
Backport of e13b71403bd1568abed237858127677144d43d23 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32304#comment:12>