Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #29570 - Added check that MEDIA_URL isn't in STATIC_URL #10201

Merged
merged 1 commit into from
Aug 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions django/contrib/staticfiles/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ def check_settings(base_url=None):
if settings.MEDIA_URL == base_url:
raise ImproperlyConfigured("The MEDIA_URL and STATIC_URL "
"settings must have different values")
if (settings.DEBUG and settings.MEDIA_URL and settings.STATIC_URL and
settings.MEDIA_URL.startswith(settings.STATIC_URL)):
raise ImproperlyConfigured(
"runserver can't serve media if MEDIA_URL is within STATIC_URL."
)
if ((settings.MEDIA_ROOT and settings.STATIC_ROOT) and
(settings.MEDIA_ROOT == settings.STATIC_ROOT)):
raise ImproperlyConfigured("The MEDIA_ROOT and STATIC_ROOT "
Expand Down
14 changes: 14 additions & 0 deletions tests/staticfiles_tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django.contrib.staticfiles.utils import check_settings
from django.core.exceptions import ImproperlyConfigured
from django.test import SimpleTestCase, override_settings


class CheckSettingsTests(SimpleTestCase):

@override_settings(DEBUG=True, MEDIA_URL='/static/media/', STATIC_URL='/static/',)
def test_media_url_in_static_url(self):
msg = "runserver can't serve media if MEDIA_URL is within STATIC_URL."
with self.assertRaisesMessage(ImproperlyConfigured, msg):
check_settings()
with self.settings(DEBUG=False): # Check disabled if DEBUG=False.
check_settings()