summaryrefslogtreecommitdiff
path: root/django/forms/widgets.py
diff options
context:
space:
mode:
authorJohannes Hoppe <info@johanneshoppe.com>2015-11-07 12:24:38 +0100
committerTim Graham <timograham@gmail.com>2015-12-10 14:30:19 -0500
commitcf546e11ac76c8dec527e39ff8ce8249a195ab42 (patch)
treec86d039e94099e47382bbeaf4361fef22bbcf55e /django/forms/widgets.py
parent6be9589eb34f79914666c9d9e1e15bdb7fc44df2 (diff)
Fixed #21221 -- Made form Media and static template tag use staticfiles if installed.
Diffstat (limited to 'django/forms/widgets.py')
-rw-r--r--django/forms/widgets.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/django/forms/widgets.py b/django/forms/widgets.py
index 3e6de0455c..f52ced26c1 100644
--- a/django/forms/widgets.py
+++ b/django/forms/widgets.py
@@ -11,6 +11,7 @@ from itertools import chain
from django.conf import settings
from django.forms.utils import flatatt, to_current_timezone
+from django.templatetags.static import static
from django.utils import datetime_safe, formats, six
from django.utils.datastructures import MultiValueDict
from django.utils.dates import MONTHS
@@ -21,7 +22,6 @@ from django.utils.formats import get_format
from django.utils.html import conditional_escape, format_html, html_safe
from django.utils.safestring import mark_safe
from django.utils.six.moves import range
-from django.utils.six.moves.urllib.parse import urljoin
from django.utils.translation import ugettext_lazy
__all__ = (
@@ -77,12 +77,15 @@ class Media(object):
) for path in self._css[medium]
] for medium in media])
- def absolute_path(self, path, prefix=None):
+ def absolute_path(self, path):
+ """
+ Given a relative or absolute path to a static asset, return an absolute
+ path. An absolute path will be returned unchanged while a relative path
+ will be passed to django.templatetags.static.static().
+ """
if path.startswith(('http://', 'https://', '/')):
return path
- if prefix is None:
- prefix = settings.STATIC_URL
- return urljoin(prefix, path)
+ return static(path)
def __getitem__(self, name):
"Returns a Media object that only contains media of the given type"