Fixed #16629 -- Relaxed check for STATIC_ROOT and STATIC_URL settings slightly to only raise an exception if really needed.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16617 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jannis Leidel 2011-08-14 18:15:04 +00:00
parent a13de6cd76
commit 2980f2ab9a
2 changed files with 13 additions and 11 deletions

View File

@ -30,17 +30,17 @@ class StaticFilesStorage(FileSystemStorage):
location = settings.STATIC_ROOT location = settings.STATIC_ROOT
if base_url is None: if base_url is None:
base_url = settings.STATIC_URL base_url = settings.STATIC_URL
if not location: check_settings(base_url)
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()
super(StaticFilesStorage, self).__init__(location, base_url, super(StaticFilesStorage, self).__init__(location, base_url,
*args, **kwargs) *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): class CachedFilesMixin(object):
patterns = ( patterns = (

View File

@ -37,16 +37,18 @@ def get_files(storage, ignore_patterns=None, location=''):
for fn in get_files(storage, ignore_patterns, dir): for fn in get_files(storage, ignore_patterns, dir):
yield fn yield fn
def check_settings(): def check_settings(base_url=None):
""" """
Checks if the staticfiles settings have sane values. 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( raise ImproperlyConfigured(
"You're using the staticfiles app " "You're using the staticfiles app "
"without having set the required STATIC_URL setting.") "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 " raise ImproperlyConfigured("The MEDIA_URL and STATIC_URL "
"settings must have different values") "settings must have different values")
if ((settings.MEDIA_ROOT and settings.STATIC_ROOT) and if ((settings.MEDIA_ROOT and settings.STATIC_ROOT) and