askrobots / dbbasic-examples
Public
Example DBBasic apps (an API, a blog and a microblog) and a template for new DBBasic modules.
danq9
Add official module template for creating DBBasic packages
17cf88a
1 year, 1 month ago
History
new.py · 639 bytes · 20 lines
| 1 | from dbbasic.tsv import TSV |
| 2 | from dbbasic_web.responses import html, redirect |
| 3 | from dbbasic_web.templating import render |
| 4 | import time |
| 5 | |
| 6 | posts = TSV("posts", ["id", "title", "content", "author", "created"]) |
| 7 | |
| 8 | def handle(request): |
| 9 | if request.method == 'POST': |
| 10 | post_id = str(int(time.time() * 1000)) |
| 11 | posts.insert({ |
| 12 | 'id': post_id, |
| 13 | 'title': request.param('title', ''), |
| 14 | 'content': request.param('content', ''), |
| 15 | 'author': request.param('author', ''), |
| 16 | 'created': time.strftime('%Y-%m-%d %H:%M') |
| 17 | }) |
| 18 | return redirect('/') |
| 19 | |
| 20 | return html(render('new.html')) |