heyogit

fireup / example-guestbook read public

fireme example: a Flask + SQLite guestbook with no Dockerfile

A Flask + SQLite guestbook

Browse files
ACapplb:claude-code-fireupcommitted 2 months ago · Oct 19, 2026· committed by heyo remotecommit f9dd3f76360210d194dab541f04dbf47c83a90eb

Showing 3 changed files with 59 additions and 0 deletions.

addedREADME.md+10−0View file
@@ -0,0 +1,10 @@
+# guestbook
+
+A one-page guestbook: a form to sign it and the last 50 entries, kept in SQLite.
+
+```sh
+pip install -r requirements.txt
+python app.py
+```
+
+It listens on `$PORT` (default 5000) and keeps its database at `$GUESTBOOK_DB` (default `guestbook.db`).
addedapp.py+48−0View file
@@ -0,0 +1,48 @@
+import html
+import os
+import sqlite3
+
+from flask import Flask, redirect, request
+
+DB = os.environ.get("GUESTBOOK_DB", "guestbook.db")
+app = Flask(__name__)
+
+
+def db():
+ conn = sqlite3.connect(DB)
+ conn.execute(
+ "CREATE TABLE IF NOT EXISTS entries "
+ "(id INTEGER PRIMARY KEY, name TEXT, message TEXT, at TEXT DEFAULT CURRENT_TIMESTAMP)"
+ )
+ return conn
+
+
+@app.get("/")
+def index():
+ with db() as conn:
+ rows = conn.execute("SELECT name, message, at FROM entries ORDER BY id DESC LIMIT 50").fetchall()
+ items = "".join(
+ f"<li><b>{html.escape(n)}</b>: {html.escape(m)} <small>{a}</small></li>" for n, m, a in rows
+ )
+ return (
+ "<!doctype html><title>Guestbook</title><h1>Guestbook</h1>"
+ "<form method=post action=/sign>"
+ "<input name=name placeholder=Name required> "
+ "<input name=message placeholder=Message required> "
+ "<button>Sign</button></form>"
+ f"<ul>{items}</ul>"
+ )
+
+
+@app.post("/sign")
+def sign():
+ with db() as conn:
+ conn.execute(
+ "INSERT INTO entries (name, message) VALUES (?, ?)",
+ (request.form["name"][:80], request.form["message"][:500]),
+ )
+ return redirect("/", code=303)
+
+
+if __name__ == "__main__":
+ app.run(host="0.0.0.0", port=int(os.environ.get("PORT", "5000")))
addedrequirements.txt+1−0View file
@@ -0,0 +1 @@
+flask==3.0.3