-
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.
More FH by Example, start Getting Started FH video tutorial
- Loading branch information
1 parent
f9e801f
commit 20eb716
Showing
8 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,10 @@ | ||
from fasthtml import * | ||
|
||
# App with custom styling to override the pico defaults | ||
css = Style(":root { --pico-font-size: 100%; --pico-font-family: Pacifico, cursive;}") | ||
app = FastHTML(hdrs=(picolink, css)) | ||
|
||
|
||
@app.route("/") | ||
def get(): | ||
return Title("Hello World"), Main(H1("Hello, World"), cls="container") |
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,29 @@ | ||
from fasthtml.common import * | ||
|
||
app = FastHTML() | ||
messages = ["This is a message, which will get rendered as a paragraph"] | ||
|
||
|
||
@app.get("/") | ||
def home(): | ||
return Main( | ||
H1("Messages"), | ||
*[P(msg) for msg in messages], | ||
A("Link to Page 2 (to add messages)", href="/page2"), | ||
) | ||
|
||
|
||
@app.get("/page2") | ||
def page2(): | ||
return Main( | ||
P("Add a message with the form below:"), | ||
Form( | ||
Input(type="text", name="data"), Button("Submit"), action="/", method="post" | ||
), | ||
) | ||
|
||
|
||
@app.post("/") | ||
def add_message(data: str): | ||
messages.append(data) | ||
return home() |
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,24 @@ | ||
from fasthtml import * | ||
|
||
app = FastHTML() | ||
|
||
count = 0 | ||
|
||
|
||
@app.get("/") | ||
def home(): | ||
return Title("Count Demo"), Main( | ||
H1("Count Demo"), | ||
P(f"Count is set to {count}", id="count"), | ||
Button( | ||
"Increment", hx_post="/increment", hx_target="#count", hx_swap="innerHTML" | ||
), | ||
) | ||
|
||
|
||
@app.post("/increment") | ||
def increment(): | ||
print("incrementing") | ||
global count | ||
count += 1 | ||
return f"Count is set to {count}" |
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,25 @@ | ||
from fasthtml.common import * | ||
|
||
app, rt = fast_app(live=True) | ||
|
||
def NumList(n): | ||
return Ul(*[Li(i+1) for i in range(n)]) | ||
|
||
@rt("/") | ||
def get(): | ||
return Titled( | ||
"My Numbers", | ||
P("Do you like these numbers?"), | ||
NumList(7), | ||
A("Change", href="/change"), | ||
) | ||
|
||
@rt("/change") | ||
def get(): | ||
return Titled( | ||
"Change", | ||
P("Change is good!"), | ||
A("Back", href="/"), | ||
) | ||
|
||
serve() |
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