]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
📝 Update includes in `docs/en/docs/tutorial/path-params.md` (#12811)
authorAlex Wendland <a.p.wendland@gmail.com>
Sat, 9 Nov 2024 14:19:27 +0000 (14:19 +0000)
committerGitHub <noreply@github.com>
Sat, 9 Nov 2024 14:19:27 +0000 (14:19 +0000)
docs/en/docs/tutorial/path-params.md

index fd9e745856fc427a00d246b8983317758acc3e9e..7e83d3ae57e7f4ef8f5ccc6e8783881a7c72e7f9 100644 (file)
@@ -2,9 +2,7 @@
 
 You can declare path "parameters" or "variables" with the same syntax used by Python format strings:
 
-```Python hl_lines="6-7"
-{!../../docs_src/path_params/tutorial001.py!}
-```
+{* ../../docs_src/path_params/tutorial001.py hl[6:7] *}
 
 The value of the path parameter `item_id` will be passed to your function as the argument `item_id`.
 
@@ -18,9 +16,7 @@ So, if you run this example and go to <a href="http://127.0.0.1:8000/items/foo"
 
 You can declare the type of a path parameter in the function, using standard Python type annotations:
 
-```Python hl_lines="7"
-{!../../docs_src/path_params/tutorial002.py!}
-```
+{* ../../docs_src/path_params/tutorial002.py hl[7] *}
 
 In this case, `item_id` is declared to be an `int`.
 
@@ -123,17 +119,13 @@ And then you can also have a path `/users/{user_id}` to get data about a specifi
 
 Because *path operations* are evaluated in order, you need to make sure that the path for `/users/me` is declared before the one for `/users/{user_id}`:
 
-```Python hl_lines="6  11"
-{!../../docs_src/path_params/tutorial003.py!}
-```
+{* ../../docs_src/path_params/tutorial003.py hl[6,11] *}
 
 Otherwise, the path for `/users/{user_id}` would match also for `/users/me`, "thinking" that it's receiving a parameter `user_id` with a value of `"me"`.
 
 Similarly, you cannot redefine a path operation:
 
-```Python hl_lines="6  11"
-{!../../docs_src/path_params/tutorial003b.py!}
-```
+{* ../../docs_src/path_params/tutorial003b.py hl[6,11] *}
 
 The first one will always be used since the path matches first.
 
@@ -149,9 +141,7 @@ By inheriting from `str` the API docs will be able to know that the values must
 
 Then create class attributes with fixed values, which will be the available valid values:
 
-```Python hl_lines="1  6-9"
-{!../../docs_src/path_params/tutorial005.py!}
-```
+{* ../../docs_src/path_params/tutorial005.py hl[1,6:9] *}
 
 /// info
 
@@ -169,9 +159,7 @@ If you are wondering, "AlexNet", "ResNet", and "LeNet" are just names of Machine
 
 Then create a *path parameter* with a type annotation using the enum class you created (`ModelName`):
 
-```Python hl_lines="16"
-{!../../docs_src/path_params/tutorial005.py!}
-```
+{* ../../docs_src/path_params/tutorial005.py hl[16] *}
 
 ### Check the docs
 
@@ -187,17 +175,13 @@ The value of the *path parameter* will be an *enumeration member*.
 
 You can compare it with the *enumeration member* in your created enum `ModelName`:
 
-```Python hl_lines="17"
-{!../../docs_src/path_params/tutorial005.py!}
-```
+{* ../../docs_src/path_params/tutorial005.py hl[17] *}
 
 #### Get the *enumeration value*
 
 You can get the actual value (a `str` in this case) using `model_name.value`, or in general, `your_enum_member.value`:
 
-```Python hl_lines="20"
-{!../../docs_src/path_params/tutorial005.py!}
-```
+{* ../../docs_src/path_params/tutorial005.py hl[20] *}
 
 /// tip
 
@@ -211,9 +195,7 @@ You can return *enum members* from your *path operation*, even nested in a JSON
 
 They will be converted to their corresponding values (strings in this case) before returning them to the client:
 
-```Python hl_lines="18  21  23"
-{!../../docs_src/path_params/tutorial005.py!}
-```
+{* ../../docs_src/path_params/tutorial005.py hl[18,21,23] *}
 
 In your client you will get a JSON response like:
 
@@ -252,9 +234,7 @@ In this case, the name of the parameter is `file_path`, and the last part, `:pat
 
 So, you can use it with:
 
-```Python hl_lines="6"
-{!../../docs_src/path_params/tutorial004.py!}
-```
+{* ../../docs_src/path_params/tutorial004.py hl[6] *}
 
 /// tip