Python

GUI Programming with
      Python and Qt


Quick Links

Home
Python index
Database Objects
Kura (now maintained by Peter Bouda)
CGI scripting and MySQL
Kpybrowser
Python + KDE Tutorial
Python + KDE Resources
PyKDE example programs
Python and Qt2
PyKDE and PyQt news
A population simulation with Stackless Python
Drift: a language simulation in Python
Anonymous CVS access


View the code

db.py
html.py
lex_valdyan.py

This code has been htmlified by vim.


Download cgi.zip


Changes

  • 27-03-2000 - Creation

© 2000 Boudewijn Rempt
 

CGI scripting and MySQL


One of my first projects was the scripting of a small CGI application for my wife, an on-line dictionary of the Valdyan Language. The application consists of a MySQL database, a CGI script for entering, updating and querying data and a report script to generate static html files because Irina doesn't want the whole world to be able to mess with her dictionary!

I already had a similar application written in Free Pascal, and all I did was to translate that application into Python. Since then, several people, beginners just like I was, have expressed an interest in that code, and that's why I present it here, annotated and well.

As you can see from the kpybrowser screenshot below, there are three modules: db.py, html.py and lex_valdyas.py.

db.py connects to the database and is a very, very simple wrapper around MySQLmodule - which is a fairly old and unsupported binding to MySQL. Nowadays I use MySQLdb, which however returns the queried rows in a different format.

html.py is a utility module that contains a lot of functions to simplify the generation of valid html.

lex_valdyan.py is the script called by the webserver. It performs the database actions and generates the response forms. Nowadays I would split this into two modules, but it serves its function.

The file v2html.py is a simple report that exports the contents of the database to html files. The file create_table.sql creates the datamodel, such as it is.