diff --git a/django/core/management/commands/runserver.py b/django/core/management/commands/runserver.py
index b63b57a..55c7869 100644
a
|
b
|
from django.core.handlers.wsgi import WSGIHandler
|
9 | 9 | from django.core.servers.basehttp import AdminMediaHandler, run, WSGIServerException |
10 | 10 | from django.utils import autoreload |
11 | 11 | |
12 | | naiveip_re = r'^(?:(?P<addr>\d{1,3}(?:\.\d{1,3}){3}|\[[a-fA-F0-9:]+\]):)?(?P<port>\d+)$' |
| 12 | naiveip_re = re.compile(r"""^(?: |
| 13 | (?P<addr> |
| 14 | (?P<ipv4>\d{1,3}(?:\.\d{1,3}){3}) | # IPv4 address |
| 15 | (?P<ipv6>\[[a-fA-F0-9:]+\]) | # IPv6 address |
| 16 | (?P<fqdn>[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*) # FQDN |
| 17 | ):)?(?P<port>\d+)$""", re.X) |
13 | 18 | DEFAULT_PORT = "8000" |
14 | 19 | |
15 | 20 | class BaseRunserverCommand(BaseCommand): |
… |
… |
class BaseRunserverCommand(BaseCommand):
|
33 | 38 | |
34 | 39 | def handle(self, addrport='', *args, **options): |
35 | 40 | self.use_ipv6 = options.get('use_ipv6') |
36 | | if self.use_ipv6 and not hasattr(socket, 'AF_INET6'): |
| 41 | if self.use_ipv6 and not socket.has_ipv6: |
37 | 42 | raise CommandError('Your Python does not support IPv6.') |
38 | 43 | if args: |
39 | 44 | raise CommandError('Usage is runserver %s' % self.args) |
| 45 | self._raw_ipv6 = False |
40 | 46 | if not addrport: |
41 | 47 | self.addr = '' |
42 | 48 | self.port = DEFAULT_PORT |
43 | 49 | else: |
44 | 50 | m = re.match(naiveip_re, addrport) |
45 | 51 | if m is None: |
46 | | raise CommandError('%r is not a valid port number' |
| 52 | raise CommandError('"%s" is not a valid port number ' |
47 | 53 | 'or address:port pair.' % addrport) |
48 | | self.addr, self.port = m.groups() |
| 54 | self.addr, _ipv4, _ipv6, _fqdn, self.port = m.groups() |
49 | 55 | if not self.port.isdigit(): |
50 | 56 | raise CommandError("%r is not a valid port number." % self.port) |
51 | 57 | if self.addr: |
52 | | if self.addr.startswith('[') and self.addr.endswith(']'): |
| 58 | if _ipv6: |
53 | 59 | self.addr = self.addr[1:-1] |
54 | 60 | self.use_ipv6 = True |
55 | | elif self.use_ipv6: |
56 | | raise CommandError('IPv6 addresses must be surrounded ' |
57 | | 'with brackets, e.g. [::1].') |
| 61 | self._raw_ipv6 = True |
| 62 | elif self.use_ipv6 and not _fqdn: |
| 63 | raise CommandError('"%s" is not a valid IPv6 address.' % self.addr) |
58 | 64 | if not self.addr: |
59 | 65 | self.addr = self.use_ipv6 and '::1' or '127.0.0.1' |
60 | 66 | self.run(*args, **options) |
… |
… |
class BaseRunserverCommand(BaseCommand):
|
86 | 92 | ) % { |
87 | 93 | "version": self.get_version(), |
88 | 94 | "settings": settings.SETTINGS_MODULE, |
89 | | "addr": self.use_ipv6 and '[%s]' % self.addr or self.addr, |
| 95 | "addr": self._raw_ipv6 and '[%s]' % self.addr or self.addr, |
90 | 96 | "port": self.port, |
91 | 97 | "quit_command": quit_command, |
92 | 98 | }) |
diff --git a/docs/ref/django-admin.txt b/docs/ref/django-admin.txt
index 0985620..1150acb 100644
a
|
b
|
Example usage::
|
616 | 616 | |
617 | 617 | Run a FastCGI server as a daemon and write the spawned PID in a file. |
618 | 618 | |
619 | | runserver [port or ipaddr:port] |
| 619 | runserver [port or address:port] |
620 | 620 | ------------------------------- |
621 | 621 | |
622 | 622 | .. django-admin:: runserver |
… |
… |
machines on the network, use its own IP address (e.g. ``192.168.2.1``) or
|
653 | 653 | |
654 | 654 | .. versionchanged:: 1.3 |
655 | 655 | |
656 | | You can also provide an IPv6 address surrounded by brackets |
657 | | (eg. ``[200a::1]:8000``). This will automaticaly enable IPv6 support. |
| 656 | You can provide an IPv6 address surrounded by brackets |
| 657 | (e.g. ``[200a::1]:8000``). This will automatically enable IPv6 support. |
| 658 | |
| 659 | A hostname containing ASCII-only characters can also be used. |
658 | 660 | |
659 | 661 | .. django-admin-option:: --adminmedia |
660 | 662 | |
… |
… |
Port 7000 on IPv6 address ``2001:0db8:1234:5678::9``::
|
721 | 723 | |
722 | 724 | django-admin.py runserver [2001:0db8:1234:5678::9]:7000 |
723 | 725 | |
| 726 | Port 8000 on IPv4 address of host ``localhost``:: |
| 727 | |
| 728 | django-admin.py runserver localhost:8000 |
| 729 | |
| 730 | Port 8000 on IPv6 address of host ``localhost``:: |
| 731 | |
| 732 | django-admin.py runserver -6 localhost:8000 |
| 733 | |
724 | 734 | Serving static files with the development server |
725 | 735 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
726 | 736 | |