Skip to content

Commit

Permalink
Doing the FH by Example tutorial again
Browse files Browse the repository at this point in the history
  • Loading branch information
audreyfeldroy committed Jul 31, 2024
1 parent ed06a95 commit 4b176f1
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 0 deletions.
8 changes: 8 additions & 0 deletions apps/01_simple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from fasthtml import FastHTML

app = FastHTML()


@app.get("/")
def home():
return "<h1>Hello, World</h1>"
8 changes: 8 additions & 0 deletions apps/02_constructing_html.py
Original file line number Diff line number Diff line change
@@ -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"))

12 changes: 12 additions & 0 deletions apps/03_routes.py
Original file line number Diff line number Diff line change
@@ -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"
74 changes: 74 additions & 0 deletions nbs/2024-07-29-FH-by-Example.ipynb
Original file line number Diff line number Diff line change
@@ -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": [
"'<!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'"
]
},
"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
}

0 comments on commit 4b176f1

Please sign in to comment.