Code

Ticket #360: django-server-addr.2.diff

File django-server-addr.2.diff, 2.7 KB (added by benno@…, 9 years ago)

Fixed version (fixes up empty addr string)

Line 
1Index: django/bin/django-admin.py
2===================================================================
3--- django/bin/django-admin.py  (revision 535)
4+++ django/bin/django-admin.py  (working copy)
5@@ -87,10 +87,15 @@
6         ACTION_MAPPING[action](name, os.getcwd())
7     elif action == 'runserver':
8         if len(args) < 2:
9+            addr = ''
10             port = '8000'
11         else:
12-            port = args[1]
13-        ACTION_MAPPING[action](port)
14+            if args[1].find(':') != -1:
15+                addr, port = args[1].split(':')
16+            else:
17+                addr = ''
18+                port = args[1]
19+        ACTION_MAPPING[action](addr, port)
20     else:
21         from django.core import meta
22         if action == 'dbcheck':
23Index: django/core/servers/basehttp.py
24===================================================================
25--- django/core/servers/basehttp.py     (revision 535)
26+++ django/core/servers/basehttp.py     (working copy)
27@@ -636,8 +636,8 @@
28         start_response(status, headers.items())
29         return output
30 
31-def run(port, wsgi_handler):
32-    server_address = ('', port)
33+def run(addr, port, wsgi_handler):
34+    server_address = (addr, port)
35     httpd = WSGIServer(server_address, WSGIRequestHandler)
36     httpd.set_app(wsgi_handler)
37     httpd.serve_forever()
38Index: django/core/management.py
39===================================================================
40--- django/core/management.py   (revision 535)
41+++ django/core/management.py   (working copy)
42@@ -543,22 +543,24 @@
43     print '%s error%s found.' % (num_errors, num_errors != 1 and 's' or '')
44 validate.args = ''
45 
46-def runserver(port):
47+def runserver(addr, port):
48     "Starts a lightweight Web server for development."
49     from django.core.servers.basehttp import run, AdminMediaHandler, WSGIServerException
50     from django.core.handlers.wsgi import WSGIHandler
51     if not port.isdigit():
52         sys.stderr.write("Error: %r is not a valid port number.\n" % port)
53         sys.exit(1)
54+    if addr == '':
55+        addr = '127.0.0.1'
56     def inner_run():
57         from django.conf.settings import SETTINGS_MODULE
58         print "Validating models..."
59         validate()
60         print "\nStarting server on port %s with settings module %r." % (port, SETTINGS_MODULE)
61-        print "Go to http://127.0.0.1:%s/ for Django." % port
62+        print "Go to http://%s:%s/ for Django." % (addr, port)
63         print "Quit the server with CONTROL-C (Unix) or CTRL-BREAK (Windows)."
64         try:
65-            run(int(port), AdminMediaHandler(WSGIHandler()))
66+            run(addr, int(port), AdminMediaHandler(WSGIHandler()))
67         except WSGIServerException, e:
68             # Use helpful error messages instead of ugly tracebacks.
69             ERRORS = {