1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Fixed #34068 -- Corrected output of runserver command for "0" IP address.

Thanks David Sanders for the review.
This commit is contained in:
Dhanush 2022-10-04 12:20:38 +05:30 committed by Mariusz Felisiak
parent 93d4c9ea1d
commit 9fbb5b5e16
2 changed files with 23 additions and 1 deletions

View File

@ -129,6 +129,13 @@ class Command(BaseCommand):
shutdown_message = options.get("shutdown_message", "")
quit_command = "CTRL-BREAK" if sys.platform == "win32" else "CONTROL-C"
if self._raw_ipv6:
addr = f"[{self.addr}]"
elif self.addr == "0":
addr = "0.0.0.0"
else:
addr = self.addr
if not options["skip_checks"]:
self.stdout.write("Performing system checks...\n\n")
self.check(display_num_errors=True)
@ -147,7 +154,7 @@ class Command(BaseCommand):
"version": self.get_version(),
"settings": settings.SETTINGS_MODULE,
"protocol": self.protocol,
"addr": "[%s]" % self.addr if self._raw_ipv6 else self.addr,
"addr": addr,
"port": self.port,
"quit_command": quit_command,
}

View File

@ -1587,6 +1587,21 @@ class ManageRunserver(SimpleTestCase):
call_command(self.cmd, addrport="7000")
self.assertServerSettings("127.0.0.1", "7000")
@mock.patch("django.core.management.commands.runserver.run")
@mock.patch("django.core.management.base.BaseCommand.check_migrations")
def test_zero_ip_addr(self, *mocked_objects):
call_command(
"runserver",
addrport="0:8000",
use_reloader=False,
skip_checks=True,
stdout=self.output,
)
self.assertIn(
"Starting development server at http://0.0.0.0:8000/",
self.output.getvalue(),
)
@unittest.skipUnless(socket.has_ipv6, "platform doesn't support IPv6")
def test_runner_addrport_ipv6(self):
call_command(self.cmd, addrport="", use_ipv6=True)