Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

… is empty.

Refs #19875.
  • Loading branch information...
commit 96c71d423db13825869a929b25d6b83dde67c170 1 parent 4e94c84
Tim Graham authored June 09, 2013
5  django/core/management/commands/runserver.py
@@ -40,6 +40,11 @@ def get_handler(self, *args, **options):
40 40
         return get_internal_wsgi_application()
41 41
 
42 42
     def handle(self, addrport='', *args, **options):
  43
+        from django.conf import settings
  44
+
  45
+        if not settings.DEBUG and not settings.ALLOWED_HOSTS:
  46
+            raise CommandError('You must set settings.ALLOWED_HOSTS if DEBUG is False.')
  47
+
43 48
         self.use_ipv6 = options.get('use_ipv6')
44 49
         if self.use_ipv6 and not socket.has_ipv6:
45 50
             raise CommandError('Your Python does not support IPv6.')
15  tests/admin_scripts/tests.py
@@ -1192,6 +1192,21 @@ def test_runner_ambiguous(self):
1192 1192
         self.cmd.handle(addrport="deadbeef:7654")
1193 1193
         self.assertServerSettings('deadbeef', '7654')
1194 1194
 
  1195
+class ManageRunserverEmptyAllowedHosts(AdminScriptTestCase):
  1196
+    def setUp(self):
  1197
+        self.write_settings('settings.py', sdict={
  1198
+            'ALLOWED_HOSTS': [],
  1199
+            'DEBUG': False,
  1200
+        })
  1201
+
  1202
+    def tearDown(self):
  1203
+        self.remove_settings('settings.py')
  1204
+
  1205
+    def test_empty_allowed_hosts_error(self):
  1206
+        out, err = self.run_manage(['runserver'])
  1207
+        self.assertNoOutput(out)
  1208
+        self.assertOutput(err, 'CommandError: You must set settings.ALLOWED_HOSTS if DEBUG is False.')
  1209
+
1195 1210
 
1196 1211
 ##########################################################################
1197 1212
 # COMMAND PROCESSING TESTS

0 notes on commit 96c71d4

Please sign in to comment.
Something went wrong with that request. Please try again.