| | 365 | def runserver(port): |
|---|
| | 366 | "Starts a lightweight Web server for development." |
|---|
| | 367 | from django.core.servers.basehttp import run, WSGIServerException |
|---|
| | 368 | from django.core.handlers.wsgi import WSGIHandler |
|---|
| | 369 | if not port.isdigit(): |
|---|
| | 370 | sys.stderr.write("Error: %r is not a valid port number.\n" % port) |
|---|
| | 371 | sys.exit(1) |
|---|
| | 372 | print "Starting server on port %s. Go to http://127.0.0.1:%s/ for Django." % (port, port) |
|---|
| | 373 | try: |
|---|
| | 374 | run(int(port), WSGIHandler()) |
|---|
| | 375 | except WSGIServerException, e: |
|---|
| | 376 | # Use helpful error messages instead of ugly tracebacks. |
|---|
| | 377 | ERRORS = { |
|---|
| | 378 | 13: "You don't have permission to access that port.", |
|---|
| | 379 | 98: "That port is already in use.", |
|---|
| | 380 | } |
|---|
| | 381 | try: |
|---|
| | 382 | error_text = ERRORS[e.args[0].args[0]] |
|---|
| | 383 | except (AttributeError, KeyError): |
|---|
| | 384 | error_text = str(e) |
|---|
| | 385 | sys.stderr.write("Error: %s\n" % error_text) |
|---|
| | 386 | sys.exit(1) |
|---|
| | 387 | runserver.args = '[optional port number]' |
|---|
| | 388 | |
|---|