Skip to content

Commit 81cf119

Browse files
authored
Merge pull request #608 from achrafmam2/doc
Misc documentation fixes to the "By Example" tutorial
2 parents 8302841 + 0107fa4 commit 81cf119

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

nbs/tutorials/by_example.ipynb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,9 @@
10331033
"metadata": {},
10341034
"outputs": [],
10351035
"source": [
1036+
"from fasthtml.common import *\n",
1037+
"from starlette.testclient import TestClient\n",
1038+
"\n",
10361039
"app = FastHTML()\n",
10371040
"cli = TestClient(app)"
10381041
]
@@ -1093,7 +1096,7 @@
10931096
"source": [
10941097
"reg_re_param(\"imgext\", \"ico|gif|jpg|jpeg|webm\")\n",
10951098
"\n",
1096-
"@app.get(r'/static/{path:path}{fn}.{ext:imgext}')\n",
1099+
"@app.get(r'/static/{path:path}/{fn}.{ext:imgext}')\n",
10971100
"def get_img(fn:str, path:str, ext:str): return f\"Getting {fn}.{ext} from /{path}\"\n",
10981101
"\n",
10991102
"cli.get('/static/foo/jph.ico').text"
@@ -1179,7 +1182,7 @@
11791182
"fake_db = [{\"name\": \"Foo\"}, {\"name\": \"Bar\"}]\n",
11801183
"\n",
11811184
"@app.get(\"/items/\")\n",
1182-
"def read_item(idx:int|None = 0): return fake_db[idx]\n",
1185+
"def read_item(idx: int = 0): return fake_db[idx]\n",
11831186
"\n",
11841187
"print(cli.get('/items/?idx=1').text)"
11851188
]
@@ -1198,6 +1201,7 @@
11981201
}
11991202
],
12001203
"source": [
1204+
"# Equivalent to `/items/?idx=0`.\n",
12011205
"print(cli.get('/items/').text)"
12021206
]
12031207
},
@@ -1905,7 +1909,7 @@
19051909
"}\n",
19061910
"```\n",
19071911
"\n",
1908-
"The [AI Pictionary example](https://github.com/AnswerDotAI/fasthtml-example/tree/main/ai_pictionary) uses a larger chunk of custom JavaScript to handle the drawing canvas. It's a good example of the type of application where running code on the client side makes the most sense, but still shows how you can integrate it with FastHTML on the server side to add functionality (like the AI responses) easily.\n",
1912+
"The [AI Pictionary example](https://github.com/AnswerDotAI/fasthtml-example/tree/main/03_pictionary) uses a larger chunk of custom JavaScript to handle the drawing canvas. It's a good example of the type of application where running code on the client side makes the most sense, but still shows how you can integrate it with FastHTML on the server side to add functionality (like the AI responses) easily.\n",
19091913
"\n",
19101914
"Adding styling with custom CSS and libraries such as tailwind is done the same way we add custom JavaScript. The [doodle example](https://github.com/AnswerDotAI/fasthtml-example/tree/main/doodle) uses [Doodle.CSS](https://github.com/chr15m/DoodleCSS) to style the page in a quirky way."
19111915
]
@@ -1944,7 +1948,7 @@
19441948
"6. Fetches and displays the URL of our app.\n",
19451949
"7. By default, mounts a `/app/data` folder on the cloud to our app's root folder. The app is run in `/app` by default, so from our app anything we store in `/data` will persist across restarts.\n",
19461950
"\n",
1947-
"A final note about Railway: We can add secrets like API keys that can be accessed as environment variables from our apps via ['Variables'](https://docs.railway.app/guides/variables). For example, for the image app (TODO link), we can add a `REPLICATE_API_KEY` variable, and then in `main.py` we can access it as `os.environ['REPLICATE_API_KEY']`.\n",
1951+
"A final note about Railway: We can add secrets like API keys that can be accessed as environment variables from our apps via ['Variables'](https://docs.railway.app/guides/variables). For example, for the [image generation app](https://github.com/AnswerDotAI/fasthtml-example/tree/main/image_app_simple), we can add a `REPLICATE_API_KEY` variable, and then in `main.py` we can access it as `os.environ['REPLICATE_API_KEY']`.\n",
19481952
"\n",
19491953
"\n",
19501954
"\n",

0 commit comments

Comments
 (0)