Categories

Links

License

Creative Commons License

Unless otherwise expressly stated, all original material of whatever nature created by and included in this weblog is licensed under a Creative Commons License.

Python Webserver in 1 or 15 lines, 14.02.2008 21:10

Python Webserver in 1 line:

python -c "import SimpleHTTPServer; SimpleHTTPServer.test()"

Python Webserver in 15 lines:

import BaseHTTPServer



class WebRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):

    def do_GET(self):

        if self.path == '/foo':

            self.send_response(200)

            self.do_something()

        else: 

            self.send_error(404)

            

    def do_something(self):

        print 'hello world'

        

server = BaseHTTPServer.HTTPServer(('',80), WebRequestHandler)

server.serve_forever()

via

blog comments powered by Disqus