diff --git a/django/contrib/staticfiles/storage.py b/django/contrib/staticfiles/storage.py index e3914efdfa3..a804c5626c8 100644 --- a/django/contrib/staticfiles/storage.py +++ b/django/contrib/staticfiles/storage.py @@ -30,17 +30,17 @@ class StaticFilesStorage(FileSystemStorage): location = settings.STATIC_ROOT if base_url is None: base_url = settings.STATIC_URL - if not location: - raise ImproperlyConfigured("You're using the staticfiles app " - "without having set the STATIC_ROOT setting.") - # check for None since we might use a root URL (``/``) - if base_url is None: - raise ImproperlyConfigured("You're using the staticfiles app " - "without having set the STATIC_URL setting.") - check_settings() + check_settings(base_url) super(StaticFilesStorage, self).__init__(location, base_url, *args, **kwargs) + def path(self, name): + if not self.location: + raise ImproperlyConfigured("You're using the staticfiles app " + "without having set the STATIC_ROOT " + "setting to a filesystem path.") + return super(StaticFilesStorage, self).path(name) + class CachedFilesMixin(object): patterns = ( diff --git a/django/contrib/staticfiles/utils.py b/django/contrib/staticfiles/utils.py index 9aee9280638..55ea3cf06b8 100644 --- a/django/contrib/staticfiles/utils.py +++ b/django/contrib/staticfiles/utils.py @@ -37,16 +37,18 @@ def get_files(storage, ignore_patterns=None, location=''): for fn in get_files(storage, ignore_patterns, dir): yield fn -def check_settings(): +def check_settings(base_url=None): """ Checks if the staticfiles settings have sane values. """ - if not settings.STATIC_URL: + if base_url is not None: + base_url = settings.STATIC_URL + if not base_url: raise ImproperlyConfigured( "You're using the staticfiles app " "without having set the required STATIC_URL setting.") - if settings.MEDIA_URL == settings.STATIC_URL: + if settings.MEDIA_URL == base_url: raise ImproperlyConfigured("The MEDIA_URL and STATIC_URL " "settings must have different values") if ((settings.MEDIA_ROOT and settings.STATIC_ROOT) and