Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #360 -- runserver now takes optional 'ip:port' in addition to '…

…port'. Thanks, benno@jeamland.net

git-svn-id: http://code.djangoproject.com/svn/django/trunk@539 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 00c6acaaf30adfb77dd38bf2064ed33d314258d9 1 parent 8d6c276
@adrianholovaty adrianholovaty authored
View
8 django/bin/django-admin.py
@@ -87,10 +87,14 @@ def main():
ACTION_MAPPING[action](name, os.getcwd())
elif action == 'runserver':
if len(args) < 2:
+ addr = ''
port = '8000'
else:
- port = args[1]
- ACTION_MAPPING[action](port)
+ try:
+ addr, port = args[1].split(':')
+ except ValueError:
+ addr, port = '', args[1]
+ ACTION_MAPPING[action](addr, port)
else:
from django.core import meta
if action == 'dbcheck':
View
11 django/core/management.py
@@ -543,10 +543,12 @@ def validate():
print '%s error%s found.' % (num_errors, num_errors != 1 and 's' or '')
validate.args = ''
-def runserver(port):
+def runserver(addr, port):
"Starts a lightweight Web server for development."
from django.core.servers.basehttp import run, AdminMediaHandler, WSGIServerException
from django.core.handlers.wsgi import WSGIHandler
+ if not addr:
+ addr = '127.0.0.1'
if not port.isdigit():
sys.stderr.write("Error: %r is not a valid port number.\n" % port)
sys.exit(1)
@@ -555,15 +557,16 @@ def inner_run():
print "Validating models..."
validate()
print "\nStarting server on port %s with settings module %r." % (port, SETTINGS_MODULE)
- print "Go to http://127.0.0.1:%s/ for Django." % port
+ print "Go to http://%s:%s/ for Django." % (addr, port)
print "Quit the server with CONTROL-C (Unix) or CTRL-BREAK (Windows)."
try:
- run(int(port), AdminMediaHandler(WSGIHandler()))
+ run(addr, int(port), AdminMediaHandler(WSGIHandler()))
except WSGIServerException, e:
# Use helpful error messages instead of ugly tracebacks.
ERRORS = {
13: "You don't have permission to access that port.",
98: "That port is already in use.",
+ 99: "That IP address can't be assigned-to.",
}
try:
error_text = ERRORS[e.args[0].args[0]]
@@ -575,4 +578,4 @@ def inner_run():
sys.exit(0)
from django.utils import autoreload
autoreload.main(inner_run)
-runserver.args = '[optional port number]'
+runserver.args = '[optional port number, or ipaddr:port]'
View
4 django/core/servers/basehttp.py
@@ -636,8 +636,8 @@ def __call__(self, environ, start_response):
start_response(status, headers.items())
return output
-def run(port, wsgi_handler):
- server_address = ('', port)
+def run(addr, port, wsgi_handler):
+ server_address = (addr, port)
httpd = WSGIServer(server_address, WSGIRequestHandler)
httpd.set_app(wsgi_handler)
httpd.serve_forever()
View
18 docs/django-admin.txt
@@ -80,11 +80,12 @@ install [app app ...]
Executes the equivalent of ``sqlall`` for the given app(s).
-runserver [optional port number]
---------------------------------
+runserver [optional port number, or ipaddr:port]
+------------------------------------------------
Starts a lightweight development Web server on the local machine. By default,
-the server runs on port 8000. You can pass in a port number explicitly.
+the server runs on port 8000 on the IP address 127.0.0.1. You can pass in an
+IP address and port number explicitly.
If you run this script as a user with normal privileges (recommended), you
might not have access to start a port on a low port number. Low port numbers
@@ -103,6 +104,17 @@ them to standard output, but it won't stop the server.
You can run as many servers as you want, as long as they're on separate ports.
Just execute ``django-admin.py runserver`` more than once.
+Examples:
+~~~~~~~~~
+
+Port 7000 on IP address 127.0.0.1::
+
+ django-admin.py runserver 7000
+
+Port 7000 on IP address 1.2.3.4::
+
+ django-admin.py runserver 1.2.3.4:7000
+
sql [app app ...]
-----------------
Please sign in to comment.
Something went wrong with that request. Please try again.