Ticket #7735: runserver-ipv6-with-docs-r7920.diff

File runserver-ipv6-with-docs-r7920.diff, 4.5 KB (added by jbalonso, 7 years ago)

IPv6 support for runserver and docs against rev 7920

  • django/core/servers/basehttp.py

     
    658658        start_response(status, headers.items())
    659659        return output
    660660
    661 def run(addr, port, wsgi_handler):
     661def run(addr, port, wsgi_handler, enable_ipv6=False):
    662662    server_address = (addr, port)
    663     httpd = WSGIServer(server_address, WSGIRequestHandler)
     663    if not enable_ipv6:
     664        httpd = WSGIServer(server_address, WSGIRequestHandler)
     665    else:
     666        import socket
     667        class WSGIServerV6(WSGIServer):
     668            address_family = socket.AF_INET6
     669        httpd = WSGIServerV6(server_address, WSGIRequestHandler)
    664670    httpd.set_app(wsgi_handler)
    665671    httpd.serve_forever()
  • django/core/management/commands/runserver.py

     
    55
    66class Command(BaseCommand):
    77    option_list = BaseCommand.option_list + (
     8        make_option('--ipv6', '-6', action='store_true', dest='enable_ipv6', default=False,
     9            help='Enables IPv6 support.'),
    810        make_option('--noreload', action='store_false', dest='use_reloader', default=True,
    911            help='Tells Django to NOT use the auto-reloader.'),
    1012        make_option('--adminmedia', dest='admin_media_path', default='',
     
    2022        import django
    2123        from django.core.servers.basehttp import run, AdminMediaHandler, WSGIServerException
    2224        from django.core.handlers.wsgi import WSGIHandler
     25        enable_ipv6=options.get('enable_ipv6')
     26        if enable_ipv6:
     27                import socket
     28                if not hasattr(socket, 'AF_INET6'):
     29                        raise CommandError("This Python does not support IPv6.")
     30
    2331        if args:
    2432            raise CommandError('Usage is runserver %s' % self.args)
    2533        if not addrport:
     
    2735            port = '8000'
    2836        else:
    2937            try:
    30                 addr, port = addrport.split(':')
     38                addr, port = addrport.rsplit(':',1)
    3139            except ValueError:
    3240                addr, port = '', addrport
    3341        if not addr:
    34             addr = '127.0.0.1'
     42            if not enable_ipv6: addr = '127.0.0.1'
     43            else: addr = '::1'
    3544
    3645        if not port.isdigit():
    3746            raise CommandError("%r is not a valid port number." % port)
     
    5160            try:
    5261                path = admin_media_path or django.__path__[0] + '/contrib/admin/media'
    5362                handler = AdminMediaHandler(WSGIHandler(), path)
    54                 run(addr, int(port), handler)
     63                run(addr, int(port), handler, enable_ipv6=enable_ipv6)
    5564            except WSGIServerException, e:
    5665                # Use helpful error messages instead of ugly tracebacks.
    5766                ERRORS = {
  • docs/django-admin.txt

     
    498498Note that the default IP address, 127.0.0.1, is not accessible from other
    499499machines on your network. To make your development server viewable to other
    500500machines on the network, use its own IP address (e.g. ``192.168.2.1``) or
    501 ``0.0.0.0``.
     501``0.0.0.0`` or ``::`` (with IPv6 enabled).
    502502
    503503--adminmedia
    504504~~~~~~~~~~~~
     
    524524
    525525    django-admin.py runserver --noreload
    526526
     527--ipv6
     528~~~~~~
     529
     530Use the ``--ipv6`` option to tell Django to enable IPv6 for the development
     531server. This allows you to specify IPv6 addresses in colon-delimited form and
     532changes the default IP address from 127.0.0.1 to ::1.
     533
     534Example usage::
     535
     536    django-admin.py runserver --ipv6
     537
    527538Examples of using different ports and addresses
    528539~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    529540
     
    535546
    536547        django-admin.py runserver 1.2.3.4:8000
    537548
     549Port 8000 on IPv6 address 2001:0db8:1234:5678::9::
     550
     551        django-admin.py runserver --ipv6 2001:0db8:1234:5678::9:8000
     552
    538553Port 7000 on IP address 127.0.0.1::
    539554
    540555    django-admin.py runserver 7000
     
    543558
    544559    django-admin.py runserver 1.2.3.4:7000
    545560
     561Port 7000 on IPv6 address 2001:0db8:1234:5678::9::
     562
     563    django-admin.py runserver --ipv6 2001:0db8:1234:5678::9:7000
     564
    546565Serving static files with the development server
    547566~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    548567
Back to Top