]> git.ipfire.org Git - thirdparty/starlette.git/commitdiff
More detail on how to use convertors 862/head
authorSimon Willison <swillison@gmail.com>
Sun, 15 Mar 2020 00:51:50 +0000 (17:51 -0700)
committerGitHub <noreply@github.com>
Sun, 15 Mar 2020 00:51:50 +0000 (17:51 -0700)
It wasn't immediately clear to me how to use them.

docs/routing.md

index 703d6b138dad15f9a8e0568f0415288f1bab36e9..3489880a425c6805a71731271b2f037d50644926 100644 (file)
@@ -36,11 +36,21 @@ Paths can use URI templating style to capture path components.
 ```python
 Route('/users/{username}', user)
 ```
+By default this will capture characters up to the end of the path or the next `/`.
 
-Convertors for `int`, `float`, and `path` are also available:
+You can use convertors to modify what is captured. Four convertors are available:
+
+* `str` returns a string, and is the default.
+* `int` returns a Python integer.
+* `float` returns a Python float.
+* `path` returns the rest of the path, including any additional `/` characers.
+
+Convertors are used by prefixing them with a colon, like so:
 
 ```python
 Route('/users/{user_id:int}', user)
+Route('/floating-point/{number:float}', floating_point)
+Route('/uploaded/{rest_of_path:path}', uploaded)
 ```
 
 Path parameters are made available in the request, as the `request.path_params`