Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

manatlan http://manatlan.online.fr

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

python : simplest http server with cherrypy

taken from http://www.cherrypy.org/wiki/CherryPyTutorial
in the browser, return a "Hello world!" at http://localhost:8080(/index)
   1  
   2  from cherrypy import cpg
   3  
   4  class HelloWorld:
   5  
   6      @cpg.expose
   7      def index(self):
   8          return "Hello world!"
   9  
  10  cpg.root = HelloWorld()
  11  cpg.server.start()

simplest httpserver with python

responding "hello" at http://localhost:8080
   1  
   2  from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer
   3  
   4  class MyServer(BaseHTTPRequestHandler):
   5      def do_GET(self):
   6          self.send_response(200, 'OK')
   7          self.send_header('Content-type', 'text/html')
   8          self.end_headers()
   9          self.wfile.write( "hello" )
  10  
  11      @staticmethod
  12      def serve_forever(port):
  13          HTTPServer(('', port), MyServer).serve_forever()
  14  
  15  if __name__ == "__main__":
  16      MyServer.serve_forever(8080)
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS