@@ -362,6 +362,30 @@ def startapp(app_name, directory):
362362startapp .help_doc = "Creates a Django app directory structure for the given app name in the current directory."
363363startapp .args = "[appname]"
364364
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+
365389def usage ():
366390 sys .stderr .write ("Usage: %s [action]\n " % sys .argv [0 ])
367391
@@ -376,6 +400,7 @@ def usage():
376400ACTION_MAPPING = {
377401 'adminindex' : get_admin_index ,
378402# 'dbcheck': database_check,
403+ 'runserver' : runserver ,
379404 'sql' : get_sql_create ,
380405 'sqlall' : get_sql_all ,
381406 'sqlclear' : get_sql_delete ,
@@ -406,6 +431,12 @@ def usage():
406431 usage ()
407432 ACTION_MAPPING [action ](name , os .getcwd ())
408433 sys .exit (0 )
434+ elif action == 'runserver' :
435+ if len (sys .argv ) < 3 :
436+ port = '8000'
437+ else :
438+ port = sys .argv [2 ]
439+ ACTION_MAPPING [action ](port )
409440 elif action == 'dbcheck' :
410441 from django .core import meta
411442 mod_list = meta .get_all_installed_modules ()
0 commit comments