python
import web
from web.contrib.template import render_jinja
from pydblite import Base
python
db = Base('datafile.pdl')
python
urls = (
'/', 'index',
'/add', 'add',
'/delete/(.+)/', 'delete',
'/edit/(.+)/', 'edit',
)
app = web.application(urls, globals())
python
db.create('items', 'name', 'description')
python
class index:
def GET(self):
items = db['items']
return render.index(items)
class add:
def POST(self):
i = web.input()
db['items'].insert(name=i.name, description=i.description)
raise web.seeother('/')
class delete:
def GET(self, item_id):
db['items'].delete(int(item_id))
raise web.seeother('/')
class edit:
def POST(self, item_id):
i = web.input()
db['items'][int(item_id)] = dict(name=i.name, description=i.description)
raise web.seeother('/')
html
<!DOCTYPE html>
<html>
<head>
<title>PyDBLiteWebPy Example</title>
</head>
<body>
<ul>
$for item in items:
<li>
$item['name']: $item['description']
<a href="/edit/$item['id']/">Edit</a>
<a href="/delete/$item['id']/">Delete</a>
</li>
$end
</ul>
<form method="post" action="/add">
<input type="text" name="name" placeholder="Item name"><br>
<textarea name="description" placeholder="Item description"></textarea><br>
<input type="submit" value="Add">
</form>
</body>
</html>