Code

Ticket #360: django-server-addr.diff

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

Patch to add ip:port as well as port argument to runserver.

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,7 +543,7 @@
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@@ -555,10 +555,10 @@
52         print "Validating models..."
53         validate()
54         print "\nStarting server on port %s with settings module %r." % (port, SETTINGS_MODULE)
55-        print "Go to http://127.0.0.1:%s/ for Django." % port
56+        print "Go to http://%s:%s/ for Django." % (addr, port)
57         print "Quit the server with CONTROL-C (Unix) or CTRL-BREAK (Windows)."
58         try:
59-            run(int(port), AdminMediaHandler(WSGIHandler()))
60+            run(addr, int(port), AdminMediaHandler(WSGIHandler()))
61         except WSGIServerException, e:
62             # Use helpful error messages instead of ugly tracebacks.
63             ERRORS = {