from fasthtml.common import *
FastHTML by Example
Studying https://docs.fastht.ml/tutorials/by_example.html more
= FastHTML() app
@app.get("/")
def home():
return Div(H1('Hello, World'), P('Some text'), P('Some more text'))
from starlette.testclient import TestClient
= TestClient(app)
client = client.get("/")
r r.text
'<!doctype html></!doctype>\n\n<html>\n <head>\n <title>FastHTML page</title>\n <meta charset="utf-8"></meta>\n <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover"></meta>\n <script src="https://unpkg.com/htmx.org@next/dist/htmx.min.js"></script>\n <script src="https://cdn.jsdelivr.net/gh/answerdotai/surreal@1.3.0/surreal.js"></script>\n <script src="https://cdn.jsdelivr.net/gh/gnat/css-scope-inline@main/script.js"></script>\n </head>\n <body>\n<div>\n <h1>Hello, World</h1>\n <p>Some text</p>\n <p>Some more text</p>\n</div>\n </body>\n</html>\n'
Forms
type="text", name="data"),
Form(Input("Submit"),
Button(="/", method="post") action
form action="/" method="post">
<input type="text" name="data">
<button>Submit</button>
<form> </