Skip to content

Instantly share code, notes, and snippets.

@axelknock
axelknock / index.html
Created January 31, 2026 23:42
Hearty minestra recipe HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Hearty Minestra Base with Cranberry Beans, Potatoes, and Pork</title>
</head>
<body>
<article>
<header>
@axelknock
axelknock / main.py
Last active January 29, 2025 22:21
Example of Datastar with FastHTML, ported from a FastAPI example
import asyncio
import json
from datetime import datetime
from fasthtml.common import *
from fasthtml.starlette import StreamingResponse
from fasthtml.core import to_xml
from datastar_py.sse import SSE_HEADERS, ServerSentEventGenerator
@axelknock
axelknock / main.py
Created November 22, 2024 18:06
Basic example of middleware to alter dataclass response from FT to json
from fasthtml.common import *
# Create middleware to handle requests ending in .json
class JSONRedirectMiddleware(MiddlewareBase):
def __init__(self, app):
self.app = app
# pass along the request with the application/json header
# if the route excepts it (as defined below, the response will be JSON)