1
0
mirror of https://github.com/django/django.git synced 2025-10-24 22:26:08 +00:00

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:
Adrian Holovaty
2005-08-19 21:23:56 +00:00
parent 8d6c276328
commit 00c6acaaf3
4 changed files with 30 additions and 11 deletions

View File

@@ -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]'

View File

@@ -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()