Aaron Swartz' web.py looks pretty good, but his framework doesn't thus far seem to support SQLite (?). Furthermore, I like using the object-relational manager SQLObject (which does support SQLite). So as I was working through the web.py tutorial, I changed the code snippets to work with SQLObject and SQLite. I store my model data in a new file, model.py, the contents of which is as follows:
from sqlobject import *
import datetime
# change the location at the end for your own purposes
sqlhub.processConnection = connectionForURI("sqlite:///home/warren/todo.db")
class Todo(SQLObject):
title=StringCol()
created=DateTimeCol(default=datetime.datetime.now)
done=BoolCol(default=False)
Then the modified code.py is as follows.
import web
from model import Todo
urls = (
'/', 'view',
'/add', 'add'
)
class view:
def GET(self):
todos=Todo.select()
web.render('view.html')
class add:
def POST(self):
i = web.input()
new=Todo(title=i.title)
web.seeother('./#t'+str(new.id))
web.internalerror = web.debugerror
if __name__ == "__main__":
web.run(urls, web.reloader)
Notice how I import from model.py, and the use of SQLObject functions. For the GET function in view, I get the data by using Todo.select() rather than using web.py's querying function. Similarly a new object is created using SQLObject rather than web.py. Also absent are database parameters (web.db_parameters) mentioned in the tutorial.
The file view.html is unchanged from the tutorial but it is included here for completeness.
<ul>
#for todo in $todos
<li id="t$todo.id">$todo.title</li>
#end for
</ul>
<form method="post" action="add">
<p><input type="text" name="title" /> <input type="submit" value="Add" /></p>
</form>
This shows that web.py certainly isn't incompatible with object-relational managers. Inspection of the source to the tutorial file (as of 30 March 2006) shows that originally Aaron had something almost identical to this, in fact also using SQLObject.
My first reaction after completing this exercise is that web.py is wonderful. It's the first web framework I've used which doesn't frustrate and annoy me.
last updated 3 years ago
#
history
<a href=" http://forums.batchblue.com/users/326 ">little kid sex</a> xjhcr <a href=" http://forums.batchblue.com/users/325 ">nymphet girls</a> smtq
1 month ago # reply