.htaccess - Questions about a simple Python web server -
import string,cgi,time os import curdir, sep basehttpserver import basehttprequesthandler, httpserver class myhandler(basehttprequesthandler): def do_get(self): try: if self.path.endswith(".html"): f = open(curdir + sep + self.path) self.send_response(200) self.send_header('content-type','text/html') self.end_headers() self.wfile.write(f.read()) f.close() return except ioerror: self.send_error(404,'file not found: %s' % self.path) def do_post(self): global rootnode try: ctype, pdict = cgi.parse_header(self.headers.getheader('content-type')) if ctype == 'multipart/form-data': query=cgi.parse_multipart(self.rfile, pdict) self.send_response(301) self.end_headers() upfilecontent = query.get('upfile') print "filecontent", upfilecontent[0] self.wfile.write("<html>post ok.<br><br>"); self.wfile.write(upfilecontent[0]); except : pass def main(): try: server = httpserver(('', 80), myhandler) print 'started httpserver...' server.serve_forever() except keyboardinterrupt: print '^c received, shutting down server' server.socket.close() if __name__ == '__main__': main()
upload.html
<html><body> <form method='post' enctype='multipart/form-data' action='http://127.0.0.1/'> file upload: <input type=file name=upfile><br> <br> <input type=submit value=press> upload file! </form> </body> </html>
questions
in upload.html, action post, so, post translate do_post on server python side?
does python server need type of htaccess rule apache server?
what
send_response(200)
mean?what's
self.wfile.write(f.read())
?
Comments
Post a Comment