diff --git a/django/core/management/commands/runserver.py b/django/core/management/commands/runserver.py
index fc2c694..2318416 100644
|
a
|
b
|
|
| 1 | 1 | from django.core.management.base import BaseCommand, CommandError |
| 2 | 2 | from optparse import make_option |
| 3 | 3 | import os |
| | 4 | import socket |
| 4 | 5 | import sys |
| 5 | 6 | |
| 6 | 7 | class Command(BaseCommand): |
| 7 | 8 | option_list = BaseCommand.option_list + ( |
| | 9 | make_option('--ipv6', '-6', action='store_true', dest='enable_ipv6', default=False, |
| | 10 | help='Enables IPv6 support.'), |
| 8 | 11 | make_option('--noreload', action='store_false', dest='use_reloader', default=True, |
| 9 | 12 | help='Tells Django to NOT use the auto-reloader.'), |
| 10 | 13 | make_option('--adminmedia', dest='admin_media_path', default='', |
| … |
… |
class Command(BaseCommand):
|
| 20 | 23 | import django |
| 21 | 24 | from django.core.servers.basehttp import run, AdminMediaHandler, WSGIServerException |
| 22 | 25 | 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 | |
| 23 | 30 | if args: |
| 24 | 31 | raise CommandError('Usage is runserver %s' % self.args) |
| 25 | 32 | if not addrport: |
| … |
… |
class Command(BaseCommand):
|
| 27 | 34 | port = '8000' |
| 28 | 35 | else: |
| 29 | 36 | try: |
| 30 | | addr, port = addrport.split(':') |
| | 37 | addr, port = addrport.rsplit(':', 1) |
| 31 | 38 | except ValueError: |
| 32 | 39 | addr, port = '', addrport |
| 33 | 40 | if not addr: |
| 34 | | addr = '127.0.0.1' |
| | 41 | addr = (enable_ipv6 and '::1') or '127.0.0.1' |
| 35 | 42 | |
| 36 | 43 | if not port.isdigit(): |
| 37 | 44 | raise CommandError("%r is not a valid port number." % port) |
| … |
… |
class Command(BaseCommand):
|
| 47 | 54 | print "Validating models..." |
| 48 | 55 | self.validate(display_num_errors=True) |
| 49 | 56 | 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) |
| 51 | 59 | print "Quit the server with %s." % quit_command |
| 52 | 60 | |
| 53 | 61 | # django.core.management.base forces the locale to en-us. We should |
| … |
… |
class Command(BaseCommand):
|
| 57 | 65 | |
| 58 | 66 | try: |
| 59 | 67 | handler = AdminMediaHandler(WSGIHandler(), admin_media_path) |
| 60 | | run(addr, int(port), handler) |
| | 68 | run(addr, int(port), handler, enable_ipv6=enable_ipv6) |
| 61 | 69 | except WSGIServerException, e: |
| 62 | 70 | # Use helpful error messages instead of ugly tracebacks. |
| 63 | 71 | ERRORS = { |
diff --git a/django/core/servers/basehttp.py b/django/core/servers/basehttp.py
index dae4297..49cd845 100644
|
a
|
b
|
import mimetypes
|
| 12 | 12 | import os |
| 13 | 13 | import re |
| 14 | 14 | import stat |
| | 15 | import socket |
| 15 | 16 | import sys |
| 16 | 17 | import urllib |
| 17 | 18 | |
| … |
… |
class AdminMediaHandler(object):
|
| 714 | 715 | start_response(status, headers.items()) |
| 715 | 716 | return output |
| 716 | 717 | |
| 717 | | def run(addr, port, wsgi_handler): |
| | 718 | class WSGIServerV6(WSGIServer): |
| | 719 | address_family = socket.AF_INET6 |
| | 720 | |
| | 721 | def run(addr, port, wsgi_handler, enable_ipv6=False): |
| 718 | 722 | 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) |
| 720 | 725 | httpd.set_app(wsgi_handler) |
| 721 | 726 | httpd.serve_forever() |
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.
|
| 563 | 563 | Note that the default IP address, 127.0.0.1, is not accessible from other |
| 564 | 564 | machines on your network. To make your development server viewable to other |
| 565 | 565 | machines 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). |
| 567 | 567 | |
| 568 | 568 | .. django-admin-option:: --adminmedia |
| 569 | 569 | |
| … |
… |
Example usage::
|
| 587 | 587 | |
| 588 | 588 | django-admin.py runserver --noreload |
| 589 | 589 | |
| | 590 | --ipv6 |
| | 591 | ~~~~~~ |
| | 592 | |
| | 593 | Use the ``--ipv6`` option to tell Django to enable IPv6 for the development |
| | 594 | server. This allows you to specify IPv6 addresses in colon-delimited form and |
| | 595 | changes the default IP address from 127.0.0.1 to ::1. |
| | 596 | |
| | 597 | Example usage:: |
| | 598 | |
| | 599 | django-admin.py runserver --ipv6 |
| | 600 | |
| 590 | 601 | Examples of using different ports and addresses |
| 591 | 602 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 592 | 603 | |
| … |
… |
Port 8000 on IP address 1.2.3.4::
|
| 598 | 609 | |
| 599 | 610 | django-admin.py runserver 1.2.3.4:8000 |
| 600 | 611 | |
| | 612 | Port 8000 on IPv6 address 2001:0db8:1234:5678::9:: |
| | 613 | |
| | 614 | django-admin.py runserver --ipv6 2001:0db8:1234:5678::9:8000 |
| | 615 | |
| 601 | 616 | Port 7000 on IP address 127.0.0.1:: |
| 602 | 617 | |
| 603 | 618 | django-admin.py runserver 7000 |
| … |
… |
Port 7000 on IP address 1.2.3.4::
|
| 606 | 621 | |
| 607 | 622 | django-admin.py runserver 1.2.3.4:7000 |
| 608 | 623 | |
| | 624 | Port 7000 on IPv6 address 2001:0db8:1234:5678::9:: |
| | 625 | |
| | 626 | django-admin.py runserver --ipv6 2001:0db8:1234:5678::9:7000 |
| | 627 | |
| 609 | 628 | Serving static files with the development server |
| 610 | 629 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 611 | 630 | |