Bladeren bron

add documentation for page parameters

Falko Schindler 2 jaren geleden
bovenliggende
commit
0feacddb90
1 gewijzigde bestanden met toevoegingen van 14 en 1 verwijderingen
  1. 14 1
      api_docs_and_examples.py

+ 14 - 1
api_docs_and_examples.py

@@ -607,7 +607,7 @@ With `shared=True` you can create a shared page.
 Its content is created once at startup and each client sees the *same* elements.
 Here, the displayed ID remains constant when the browser reloads the page.
 
-#### Index page
+#### Index Page
 
 All elements that are not created within a decorated page function are automatically added to a new, *shared* index page at route "/".
 To make it "private" or to change other attributes like title, favicon etc. you can wrap it in a page function with `@ui.page('/', ...)` decorator.
@@ -626,6 +626,19 @@ To make it "private" or to change other attributes like title, favicon etc. you
         ui.link('private page', private_page)
         ui.link('shared page', shared_page)
 
+    page_with_path_parameters = '''#### Pages with Path Parameters
+
+Page routes can contain parameters like [FastAPI](https://fastapi.tiangolo.com/tutorial/path-params/>).
+If type-annotated, they are automatically converted to bool, int, float and complex values.
+If the page function expects a `request` argument, the request object is automatically provided.
+'''
+    with example(page_with_path_parameters):
+        @ui.page('/repeat/{word}/{count}')
+        def page(word: str, count: int):
+            ui.label(word * count)
+
+        ui.link('Say hi to Santa!', 'repeat/Ho! /3')
+
     yield_page_ready = '''#### Yielding for Page-Ready
 
 This is a handy alternative to the `on_page_ready` callback (either as parameter of `@ui.page` or via `ui.on_page_ready` function).