summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2005-08-19 21:23:56 +0000
committerAdrian Holovaty <adrian@holovaty.com>2005-08-19 21:23:56 +0000
commit00c6acaaf30adfb77dd38bf2064ed33d314258d9 (patch)
tree0fd965d5ce232bade0c3faaca866b8b07bc5c68f
parent8d6c276328b43ab0351cbfae9bcfcacfa9fdd47d (diff)
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
-rwxr-xr-xdjango/bin/django-admin.py8
-rw-r--r--django/core/management.py11
-rw-r--r--django/core/servers/basehttp.py4
-rw-r--r--docs/django-admin.txt18
4 files changed, 30 insertions, 11 deletions
diff --git a/django/bin/django-admin.py b/django/bin/django-admin.py
index c4aa51a066..c11ed71dcb 100755
--- a/django/bin/django-admin.py
+++ b/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':
diff --git a/django/core/management.py b/django/core/management.py
index af6661fb8b..8d7d7e2a93 100644
--- a/django/core/management.py
+++ b/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 runserver(port):
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 runserver(port):
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]'
diff --git a/django/core/servers/basehttp.py b/django/core/servers/basehttp.py
index 57174e8c6e..83112ac313 100644
--- a/django/core/servers/basehttp.py
+++ b/django/core/servers/basehttp.py
@@ -636,8 +636,8 @@ class AdminMediaHandler:
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()
diff --git a/docs/django-admin.txt b/docs/django-admin.txt
index ab9a05052d..6ac15341b9 100644
--- a/docs/django-admin.txt
+++ b/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 ...]
-----------------