diff --git a/apps/01_simple.py b/apps/01_simple.py new file mode 100644 index 0000000..ea1e773 --- /dev/null +++ b/apps/01_simple.py @@ -0,0 +1,8 @@ +from fasthtml import FastHTML + +app = FastHTML() + + +@app.get("/") +def home(): + return "

Hello, World

" diff --git a/apps/02_constructing_html.py b/apps/02_constructing_html.py new file mode 100644 index 0000000..3788d0a --- /dev/null +++ b/apps/02_constructing_html.py @@ -0,0 +1,8 @@ +from fasthtml.common import * + +app = FastHTML() + +@app.get("/") +def home(): + return Div(H1("Hello, World"), P("Some text"), P("Some more text")) + diff --git a/apps/03_routes.py b/apps/03_routes.py new file mode 100644 index 0000000..6715550 --- /dev/null +++ b/apps/03_routes.py @@ -0,0 +1,12 @@ +from fasthtml.common import * + +app = FastHTML() + +@app.route("/", methods="get") +def home(): + return H1("Hello, World") + + +@app.route("/") +def post_or_put(): + return "got a POST or PUT request" diff --git a/nbs/2024-07-29-FH-by-Example.ipynb b/nbs/2024-07-29-FH-by-Example.ipynb new file mode 100644 index 0000000..835c827 --- /dev/null +++ b/nbs/2024-07-29-FH-by-Example.ipynb @@ -0,0 +1,74 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# FastHTML by Example\n", + "\n", + "I'm going through this tutorial again to learn more." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from fasthtml.common import *" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "app = FastHTML()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "@app.get(\"/\")\n", + "def home():\n", + " return Div(H1('Hello, World'), P('Some text'), P('Some more text'))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'\\n\\n\\n \\n FastHTML page\\n \\n \\n \\n \\n \\n \\n \\n
\\n

Hello, World

\\n

Some text

\\n

Some more text

\\n
\\n \\n\\n'" + ] + }, + "execution_count": null, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from starlette.testclient import TestClient\n", + "client = TestClient(app)\n", + "r = client.get(\"/\")\n", + "r.text" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "python3", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}