shell command
python -m http.server 8000
write with canvas
<!DOCTYPE html> <html> <head> </head> <body> <canvas id="c" width="500" height="500"></canvas> <script> var c = document.querySelector("#c"); var ctx = c.getContext("2d"); ctx.fillRect(100, 100, 100, 100); ctx.strokeRect(50, 50, 50, 50); </script> </body> </head> </html>
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer class WebServerHandler(BaseHTTPRequestHandler): def do_GET(self): if self.path.endswith("/hello"): self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() message = "" message += "<html><body>Hello!</body></html>" self.wfile.write(message) print message return if self.path.endswith("/hola"): self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() message = "" message += "<html><body> ¡ Hola ! <a href='/hello'>back to hello</a></body></html>" self.wfile.write(message) print message return else: self.send_error(404, 'File Not Found: %s' % self.path) def main(): try: port = 8080 server = HTTPServer(('', port), WebServerHandler) print "Web Server running on port %s" % port server.serve_forever() except KeyboardInterrupt: print " ^C entered, stopping web server...." server.socket.close() if __name__ == '__main__': main()
from flask import Flask app = Flask(__name__) @app.route('/') @app.route('/hello') def HelloWorld(): return "Hello World" if __name__ == '__main__': app.debug = True app.run(host='0.0.0.0', port=5000)