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

File runserver-ipv6-with-docs-r13350.diff, 5.3 KB (added by Łukasz Rekucki, 14 years ago)

I took the liberty to update a patch to revision 13350. One important change, is that the URL for IPv6 should be http://[address]:port/ (with brackets).

  • django/core/management/commands/runserver.py

    diff --git a/django/core/management/commands/runserver.py b/django/core/management/commands/runserver.py
    index fc2c694..2318416 100644
    a b  
    11from django.core.management.base import BaseCommand, CommandError
    22from optparse import make_option
    33import os
     4import socket
    45import sys
    56
    67class Command(BaseCommand):
    78    option_list = BaseCommand.option_list + (
     9        make_option('--ipv6', '-6', action='store_true', dest='enable_ipv6', default=False,
     10            help='Enables IPv6 support.'),
    811        make_option('--noreload', action='store_false', dest='use_reloader', default=True,
    912            help='Tells Django to NOT use the auto-reloader.'),
    1013        make_option('--adminmedia', dest='admin_media_path', default='',
    class Command(BaseCommand):  
    2023        import django
    2124        from django.core.servers.basehttp import run, AdminMediaHandler, WSGIServerException
    2225        from django.core.handlers.wsgi import WSGIHandler
     26        enable_ipv6 = options.get('enable_ipv6')
     27        if enable_ipv6 and not hasattr(socket, 'AF_INET6'):
     28            raise CommandError("This Python does not support IPv6.")
     29
    2330        if args:
    2431            raise CommandError('Usage is runserver %s' % self.args)
    2532        if not addrport:
    class Command(BaseCommand):  
    2734            port = '8000'
    2835        else:
    2936            try:
    30                 addr, port = addrport.split(':')
     37                addr, port = addrport.rsplit(':', 1)
    3138            except ValueError:
    3239                addr, port = '', addrport
    3340        if not addr:
    34             addr = '127.0.0.1'
     41            addr = (enable_ipv6 and '::1') or '127.0.0.1'
    3542
    3643        if not port.isdigit():
    3744            raise CommandError("%r is not a valid port number." % port)
    class Command(BaseCommand):  
    4754            print "Validating models..."
    4855            self.validate(display_num_errors=True)
    4956            print "\nDjango version %s, using settings %r" % (django.get_version(), settings.SETTINGS_MODULE)
    50             print "Development server is running at http://%s:%s/" % (addr, port)
     57            fmt_addr = (enable_ipv6 and '[%s]' % addr) or addr
     58            print "Development server is running at http://%s:%s/" % (fmt_addr, port)
    5159            print "Quit the server with %s." % quit_command
    5260
    5361            # django.core.management.base forces the locale to en-us. We should
    class Command(BaseCommand):  
    5765
    5866            try:
    5967                handler = AdminMediaHandler(WSGIHandler(), admin_media_path)
    60                 run(addr, int(port), handler)
     68                run(addr, int(port), handler, enable_ipv6=enable_ipv6)
    6169            except WSGIServerException, e:
    6270                # Use helpful error messages instead of ugly tracebacks.
    6371                ERRORS = {
  • django/core/servers/basehttp.py

    diff --git a/django/core/servers/basehttp.py b/django/core/servers/basehttp.py
    index dae4297..49cd845 100644
    a b import mimetypes  
    1212import os
    1313import re
    1414import stat
     15import socket
    1516import sys
    1617import urllib
    1718
    class AdminMediaHandler(object):  
    714715        start_response(status, headers.items())
    715716        return output
    716717
    717 def run(addr, port, wsgi_handler):
     718class WSGIServerV6(WSGIServer):
     719    address_family = socket.AF_INET6
     720
     721def run(addr, port, wsgi_handler, enable_ipv6=False):
    718722    server_address = (addr, port)
    719     httpd = WSGIServer(server_address, WSGIRequestHandler)
     723    server_class = (enable_ipv6 and WSGIServerV6) or WSGIServer
     724    httpd = server_class(server_address, WSGIRequestHandler)
    720725    httpd.set_app(wsgi_handler)
    721726    httpd.serve_forever()
  • docs/ref/django-admin.txt

    diff --git a/docs/ref/django-admin.txt b/docs/ref/django-admin.txt
    index 0918f5c..6f661fd 100644
    a b Just execute ``django-admin.py runserver`` more than once.  
    563563Note that the default IP address, 127.0.0.1, is not accessible from other
    564564machines on your network. To make your development server viewable to other
    565565machines on the network, use its own IP address (e.g. ``192.168.2.1``) or
    566 ``0.0.0.0``.
     566``0.0.0.0`` or ``::`` (with IPv6 enabled).
    567567
    568568.. django-admin-option:: --adminmedia
    569569
    Example usage::  
    587587
    588588    django-admin.py runserver --noreload
    589589
     590--ipv6
     591~~~~~~
     592
     593Use the ``--ipv6`` option to tell Django to enable IPv6 for the development
     594server. This allows you to specify IPv6 addresses in colon-delimited form and
     595changes the default IP address from 127.0.0.1 to ::1.
     596
     597Example usage::
     598
     599    django-admin.py runserver --ipv6
     600
    590601Examples of using different ports and addresses
    591602~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    592603
    Port 8000 on IP address 1.2.3.4::  
    598609
    599610        django-admin.py runserver 1.2.3.4:8000
    600611
     612Port 8000 on IPv6 address 2001:0db8:1234:5678::9::
     613
     614        django-admin.py runserver --ipv6 2001:0db8:1234:5678::9:8000
     615
    601616Port 7000 on IP address 127.0.0.1::
    602617
    603618    django-admin.py runserver 7000
    Port 7000 on IP address 1.2.3.4::  
    606621
    607622    django-admin.py runserver 1.2.3.4:7000
    608623
     624Port 7000 on IPv6 address 2001:0db8:1234:5678::9::
     625
     626    django-admin.py runserver --ipv6 2001:0db8:1234:5678::9:7000
     627
    609628Serving static files with the development server
    610629~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    611630
Back to Top