I'm currently coding some minor tools in python for which I'd like to have a more or less minimalistic web interface. Are there any simple and lightweight modules providing a http web server (or even web interfaces)? I don't really want to code this stuff myself, as these tools are just for little computer and file management purposes; the need to write a web server by my own would indeed outweigh the benefits from having a web interface under these circumstances.
Apache/mod_python
lighttpd/fastcgi/flup
Django (also has a development webserver)
SimpleHTTPServer
Name:
Anonymous2007-07-06 17:32 ID:ZWhTAj8Y
You seem to misunderstand me somewhat--I don't want to run a python program on a web server, I want to develop a web interface for a python program that's run locally on the computer.
I could write the http request handler and server myself, but this would be quite tedious, so I thought there might be a pre-built solution.
SimpleHTTPServer is, well, a bit too simple, since it only serves files already in directories; I'd like to have a server which just outputs a web page that is given to it via a string (or a dictionary containing strings as the values; the keys would be the page names) and reports back the values it received via HTTP_GET or HTTP_POST (ideally in a dictionary with the keys being the variable names and values being, well, the values)
Is there something like that or do I really have to code it myself?
Use BaseHTTPServer and create a subclass of BaseHTTPRequestHandler.
Name:
Anonymous2007-07-06 18:10 ID:pU5eIVZt
>>9
I think you want to subclass SimpleHTTPRequestHandler or BaseHTTPRequestHandler and override do_GET() and do_POST().
Not sure how to extract the form values, I think CGIHTTPServer deals with that somewhere.
Name:
Anonymous2007-07-06 19:42 ID:eKkxCGM3
>>11
Nope. Just subclass BaseHTTPServer, override do_GET(self), and check self.path.
eg..
def do_GET(self):
path = urllib.unquote(self.path)
try: path, query = path.split('?', 1)
except: query = ''
cgi_values = cgi.parse_qs(query)
self.wfile.write('Your name is %s' % cgi_values.get('name', [None])[0])
self.send_response(200)
self.send_header('Content-Type', 'text/plain')
self.end_headers()
(Note, I haven't actually tested this code; it's all from memory.)