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
post.py · 508 bytes · 17 lines
| 1 | from dbbasic.tsv import TSV |
| 2 | from dbbasic_web.responses import html, json_error |
| 3 | from dbbasic_web.templating import render |
| 4 | |
| 5 | posts = TSV("posts", ["id", "title", "content", "author", "created"]) |
| 6 | |
| 7 | def handle(request): |
| 8 | # /post/<post_id> |
| 9 | post_id = request.path_param(1) |
| 10 | if not post_id: |
| 11 | return json_error("Invalid path", status=404) |
| 12 | |
| 13 | post = posts.query_one(id=post_id) |
| 14 | if not post: |
| 15 | return json_error("Post not found", status=404) |
| 16 | |
| 17 | return html(render('post.html', post=post)) |