-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Doing the FH by Example tutorial again
- Loading branch information
1 parent
ed06a95
commit 4b176f1
Showing
4 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |