Ticket #360: django-server-addr.2.diff

File django-server-addr.2.diff, 2.7 KB (added by benno@…, 19 years ago)

Fixed version (fixes up empty addr string)

  • django/bin/django-admin.py

     
    8787        ACTION_MAPPING[action](name, os.getcwd())
    8888    elif action == 'runserver':
    8989        if len(args) < 2:
     90            addr = ''
    9091            port = '8000'
    9192        else:
    92             port = args[1]
    93         ACTION_MAPPING[action](port)
     93            if args[1].find(':') != -1:
     94                addr, port = args[1].split(':')
     95            else:
     96                addr = ''
     97                port = args[1]
     98        ACTION_MAPPING[action](addr, port)
    9499    else:
    95100        from django.core import meta
    96101        if action == 'dbcheck':
  • django/core/servers/basehttp.py

     
    636636        start_response(status, headers.items())
    637637        return output
    638638
    639 def run(port, wsgi_handler):
    640     server_address = ('', port)
     639def run(addr, port, wsgi_handler):
     640    server_address = (addr, port)
    641641    httpd = WSGIServer(server_address, WSGIRequestHandler)
    642642    httpd.set_app(wsgi_handler)
    643643    httpd.serve_forever()
  • django/core/management.py

     
    543543    print '%s error%s found.' % (num_errors, num_errors != 1 and 's' or '')
    544544validate.args = ''
    545545
    546 def runserver(port):
     546def runserver(addr, port):
    547547    "Starts a lightweight Web server for development."
    548548    from django.core.servers.basehttp import run, AdminMediaHandler, WSGIServerException
    549549    from django.core.handlers.wsgi import WSGIHandler
    550550    if not port.isdigit():
    551551        sys.stderr.write("Error: %r is not a valid port number.\n" % port)
    552552        sys.exit(1)
     553    if addr == '':
     554        addr = '127.0.0.1'
    553555    def inner_run():
    554556        from django.conf.settings import SETTINGS_MODULE
    555557        print "Validating models..."
    556558        validate()
    557559        print "\nStarting server on port %s with settings module %r." % (port, SETTINGS_MODULE)
    558         print "Go to http://127.0.0.1:%s/ for Django." % port
     560        print "Go to http://%s:%s/ for Django." % (addr, port)
    559561        print "Quit the server with CONTROL-C (Unix) or CTRL-BREAK (Windows)."
    560562        try:
    561             run(int(port), AdminMediaHandler(WSGIHandler()))
     563            run(addr, int(port), AdminMediaHandler(WSGIHandler()))
    562564        except WSGIServerException, e:
    563565            # Use helpful error messages instead of ugly tracebacks.
    564566            ERRORS = {
Back to Top