Skip to content

Commit

Permalink
Added 'django-admin.py runserver', which starts a lightweight develop…
Browse files Browse the repository at this point in the history
…ment server running Django on a local port

git-svn-id: http://code.djangoproject.com/svn/django/trunk@174 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
adrianholovaty committed Jul 18, 2005
1 parent fbfa3d6 commit b68c478
Show file tree
Hide file tree
Showing 3 changed files with 617 additions and 0 deletions.
31 changes: 31 additions & 0 deletions django/bin/django-admin.py
Expand Up @@ -362,6 +362,30 @@ def startapp(app_name, directory):
startapp.help_doc = "Creates a Django app directory structure for the given app name in the current directory."
startapp.args = "[appname]"

def runserver(port):
"Starts a lightweight Web server for development."
from django.core.servers.basehttp import run, WSGIServerException
from django.core.handlers.wsgi import WSGIHandler
if not port.isdigit():
sys.stderr.write("Error: %r is not a valid port number.\n" % port)
sys.exit(1)
print "Starting server on port %s. Go to http://127.0.0.1:%s/ for Django." % (port, port)
try:
run(int(port), 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.",
}
try:
error_text = ERRORS[e.args[0].args[0]]
except (AttributeError, KeyError):
error_text = str(e)
sys.stderr.write("Error: %s\n" % error_text)
sys.exit(1)
runserver.args = '[optional port number]'

def usage():
sys.stderr.write("Usage: %s [action]\n" % sys.argv[0])

Expand All @@ -376,6 +400,7 @@ def usage():
ACTION_MAPPING = {
'adminindex': get_admin_index,
# 'dbcheck': database_check,
'runserver': runserver,
'sql': get_sql_create,
'sqlall': get_sql_all,
'sqlclear': get_sql_delete,
Expand Down Expand Up @@ -406,6 +431,12 @@ def usage():
usage()
ACTION_MAPPING[action](name, os.getcwd())
sys.exit(0)
elif action == 'runserver':
if len(sys.argv) < 3:
port = '8000'
else:
port = sys.argv[2]
ACTION_MAPPING[action](port)
elif action == 'dbcheck':
from django.core import meta
mod_list = meta.get_all_installed_modules()
Expand Down
Empty file added django/core/servers/__init__.py
Empty file.

0 comments on commit b68c478

Please sign in to comment.