Question

I need to write a browser interface for an application running embedded on a single board computer (Gumstix Verdex for anyone who's interested), so I won't be able to use any web frameworks due to space and processor constraints (and availability for the environment I'm running in). I'm limited to the core Python and cgi modules to create pages that will communicate with a C++ application.

Can anyone recommend a good resource (web or book form, but books are preferred) for learning CGI programming in Python?

What I need the application to do is fairly simple. I have a C++ program running on the same device and I need to create a browser based user interface so the configuration settings of that application can be changed. The UI needs to communicate with the C++ application, where the final data validation will be done. Preliminary validation can be done on the UI using Javascript, then again on the server using Python, but the final validation has to be done in the application itself, since it's getting its initial config from a file anyway. The configuration data takes all forms (booleans, ints, floats, and strings).

Was it helpful?

Solution

It's fairly easy, this should get you up to date very quickly

http://legacy.python.org/doc/essays/ppt/sd99east/sld038.htm

OTHER TIPS

One of the biggest resources for CGI programming is the CGI homepage. Once you're done with that, familiarizing yourself with the cgi and cgitb modules should be your next task.

But don't discount learning WSGI (libref) and using a CGI-to-WSGI adaptor such as flup.

What I don't understand is why you insist on CGI, because that's a Common Gateway Interface meant to be used in conjunction with a webserver like apache, which you surely do not have on that device.

I would suggest you use wsgiref.simple_server which is a single threaded buildin webserver shipped with python 2.5 and up (if you have 2.4 or below you can d/l wsgiref from pypi, it is a pure python package). That way you can also sidestep messy CGI programming and write a wsgi application:

from wsgiref.simple_server import make_server

def application(environ, start_response):
    start_response('200 OK', [
        ('Content-Type', 'text/plain'),
    ])
    return ['Hello World!']

httpd = make_server('', 8000, application)
httpd.serve_forever()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top