Browse files

Added runserver validation to detect if DEBUG=False and ALLOWED_HOSTS…

… is empty.

Refs #19875.
  • Loading branch information...
1 parent 4e94c84 commit 96c71d423db13825869a929b25d6b83dde67c170 @timgraham timgraham committed Jun 9, 2013
Showing with 20 additions and 0 deletions.
  1. +5 −0 django/core/management/commands/runserver.py
  2. +15 −0 tests/admin_scripts/tests.py
View
5 django/core/management/commands/runserver.py
@@ -40,6 +40,11 @@ def get_handler(self, *args, **options):
return get_internal_wsgi_application()
def handle(self, addrport='', *args, **options):
+ from django.conf import settings
+
+ if not settings.DEBUG and not settings.ALLOWED_HOSTS:
+ raise CommandError('You must set settings.ALLOWED_HOSTS if DEBUG is False.')
+
self.use_ipv6 = options.get('use_ipv6')
if self.use_ipv6 and not socket.has_ipv6:
raise CommandError('Your Python does not support IPv6.')
View
15 tests/admin_scripts/tests.py
@@ -1192,6 +1192,21 @@ def test_runner_ambiguous(self):
self.cmd.handle(addrport="deadbeef:7654")
self.assertServerSettings('deadbeef', '7654')
+class ManageRunserverEmptyAllowedHosts(AdminScriptTestCase):
+ def setUp(self):
+ self.write_settings('settings.py', sdict={
+ 'ALLOWED_HOSTS': [],
+ 'DEBUG': False,
+ })
+
+ def tearDown(self):
+ self.remove_settings('settings.py')
+
+ def test_empty_allowed_hosts_error(self):
+ out, err = self.run_manage(['runserver'])
+ self.assertNoOutput(out)
+ self.assertOutput(err, 'CommandError: You must set settings.ALLOWED_HOSTS if DEBUG is False.')
+
##########################################################################
# COMMAND PROCESSING TESTS

0 comments on commit 96c71d4

Please sign in to comment.