Posts

Showing posts with the label zodb

zodb cherrypy and lxml - simple CRUD and OO database with python.

Below I have combined three python libraries to let you do a free-form CRUD document oriented database with a webserver. Where you can just pass it most any text based html form and it will be able CReate, Update, and Delete pages. In the post I made about cherrypy + zodb and python I combined the best python object database ' zodb ' with arguably the best python webserver ' cherrypy ', to create a very simple key/value datastore. This time I've combined it with lxml, to give you a very simple free form CRUD document web application. lxml is an xml library with a number of interesting features. Including a form filling library. Below is a script which uses ' lxml ' to fill in a custom form - specified in normal html - with data you have. lxml has many html/xml related stuff in it... including a css library, and is very fast. Well worth checking out if you need to do anything webby. You can define your html form, and it'll save whatever fields you h...

zodb + cherrypy python

Here's a small example of how to use cherrypy and zodb together. It just adds what ever you pass into the /put url as arguments into the db. easy_install ZODB3 easy_install cherrypy You can see the website here, once you run the script: http://localhost:8080/ import cherrypy import cgi from ZODB import FileStorage, DB import transaction class MyZODB(object): def __init__(self, path): self.storage = FileStorage.FileStorage(path) self.db = DB(self.storage) self.connection = self.db.open() self.dbroot = self.connection.root() def close(self): self.connection.close() self.db.close() self.storage.close() def ehtml(s): return cgi.escape(s) class HelloWorld(object): def index(self): # list everything passed, and allow adding more. r = "" for k,v in dbroot.items(): r += "k:%s: v:%s:<br>" % (ehtml(k), ehtml(v)) r += "<form action='put' method='post'>...