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
This commit is contained in:
parent
8d6c276328
commit
00c6acaaf3
|
@ -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':
|
||||
|
|
|
@ -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]'
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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 ...]
|
||||
-----------------
|
||||
|
||||
|
|
Loading…
Reference in New Issue