]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
🎨 Simplify docs hl_lines ranges and standardize 2 spaces between each range (#1863)
authorBrock Friedrich <brocklfriedrich@gmail.com>
Sat, 29 Aug 2020 14:02:58 +0000 (09:02 -0500)
committerGitHub <noreply@github.com>
Sat, 29 Aug 2020 14:02:58 +0000 (16:02 +0200)
79 files changed:
README.md
docs/en/docs/advanced/additional-responses.md
docs/en/docs/advanced/async-sql-databases.md
docs/en/docs/advanced/async-tests.md
docs/en/docs/advanced/behind-a-proxy.md
docs/en/docs/advanced/custom-request-and-route.md
docs/en/docs/advanced/custom-response.md
docs/en/docs/advanced/extending-openapi.md
docs/en/docs/advanced/graphql.md
docs/en/docs/advanced/middleware.md
docs/en/docs/advanced/nosql-databases.md
docs/en/docs/advanced/openapi-callbacks.md
docs/en/docs/advanced/path-operation-advanced-configuration.md
docs/en/docs/advanced/response-cookies.md
docs/en/docs/advanced/response-directly.md
docs/en/docs/advanced/response-headers.md
docs/en/docs/advanced/security/http-basic-auth.md
docs/en/docs/advanced/security/oauth2-scopes.md
docs/en/docs/advanced/settings.md
docs/en/docs/advanced/sql-databases-peewee.md
docs/en/docs/advanced/sub-applications.md
docs/en/docs/advanced/templates.md
docs/en/docs/advanced/testing-database.md
docs/en/docs/advanced/testing-dependencies.md
docs/en/docs/advanced/testing-events.md
docs/en/docs/advanced/testing-websockets.md
docs/en/docs/advanced/using-request-directly.md
docs/en/docs/advanced/websockets.md
docs/en/docs/advanced/wsgi.md
docs/en/docs/async.md
docs/en/docs/index.md
docs/en/docs/python-types.md
docs/en/docs/tutorial/background-tasks.md
docs/en/docs/tutorial/bigger-applications.md
docs/en/docs/tutorial/body-fields.md
docs/en/docs/tutorial/body-multiple-params.md
docs/en/docs/tutorial/body-nested-models.md
docs/en/docs/tutorial/body-updates.md
docs/en/docs/tutorial/body.md
docs/en/docs/tutorial/cors.md
docs/en/docs/tutorial/debugging.md
docs/en/docs/tutorial/dependencies/classes-as-dependencies.md
docs/en/docs/tutorial/dependencies/dependencies-in-path-operation-decorators.md
docs/en/docs/tutorial/dependencies/dependencies-with-yield.md
docs/en/docs/tutorial/dependencies/index.md
docs/en/docs/tutorial/dependencies/sub-dependencies.md
docs/en/docs/tutorial/encoder.md
docs/en/docs/tutorial/extra-data-types.md
docs/en/docs/tutorial/extra-models.md
docs/en/docs/tutorial/handling-errors.md
docs/en/docs/tutorial/metadata.md
docs/en/docs/tutorial/middleware.md
docs/en/docs/tutorial/path-operation-configuration.md
docs/en/docs/tutorial/path-params.md
docs/en/docs/tutorial/query-params.md
docs/en/docs/tutorial/request-files.md
docs/en/docs/tutorial/response-model.md
docs/en/docs/tutorial/response-status-code.md
docs/en/docs/tutorial/schema-extra-example.md
docs/en/docs/tutorial/security/get-current-user.md
docs/en/docs/tutorial/security/oauth2-jwt.md
docs/en/docs/tutorial/security/simple-oauth2.md
docs/en/docs/tutorial/sql-databases.md
docs/en/docs/tutorial/static-files.md
docs/en/docs/tutorial/testing.md
docs/es/docs/async.md
docs/es/docs/index.md
docs/es/docs/python-types.md
docs/it/docs/index.md
docs/pt/docs/index.md
docs/ru/docs/index.md
docs/uk/docs/index.md
docs/zh/docs/index.md
docs/zh/docs/python-types.md
docs/zh/docs/tutorial/body-fields.md
docs/zh/docs/tutorial/body-multiple-params.md
docs/zh/docs/tutorial/body.md
docs/zh/docs/tutorial/path-params.md
docs/zh/docs/tutorial/query-params.md

index 9fed5de828091e0aedc9df67a8eb21f26fbfdf97..d0b73f9fc23711ccd166d1dd931e9da050106fa0 100644 (file)
--- a/README.md
+++ b/README.md
@@ -153,7 +153,7 @@ def read_item(item_id: int, q: Optional[str] = None):
 
 If your code uses `async` / `await`, use `async def`:
 
-```Python hl_lines="9 14"
+```Python hl_lines="9  14"
 from typing import Optional
 
 from fastapi import FastAPI
@@ -245,7 +245,7 @@ Now modify the file `main.py` to receive a body from a `PUT` request.
 
 Declare the body using standard Python types, thanks to Pydantic.
 
-```Python hl_lines="4  9 10 11 12  25 26 27"
+```Python hl_lines="4  9-12  25-27"
 from typing import Optional
 
 from fastapi import FastAPI
index c8d443c3ca57075281e2ba8363bf9243829698be..4b8b3b71e3430c97e7f8fb4c30a7b6a7556cbc17 100644 (file)
@@ -23,7 +23,7 @@ Each of those response `dict`s can have a key `model`, containing a Pydantic mod
 
 For example, to declare another response with a status code `404` and a Pydantic model `Message`, you can write:
 
-```Python hl_lines="18 23"
+```Python hl_lines="18  23"
 {!../../../docs_src/additional_responses/tutorial001.py!}
 ```
 
@@ -44,7 +44,7 @@ For example, to declare another response with a status code `404` and a Pydantic
 
 The generated responses in the OpenAPI for this *path operation* will be:
 
-```JSON hl_lines="3 4 5 6 7 8 9 10 11 12"
+```JSON hl_lines="3-12"
 {
     "responses": {
         "404": {
@@ -83,7 +83,7 @@ The generated responses in the OpenAPI for this *path operation* will be:
 
 The schemas are referenced to another place inside the OpenAPI schema:
 
-```JSON hl_lines="4 5 6 7 8 9 10 11 12 13 14 15 16"
+```JSON hl_lines="4-16"
 {
     "components": {
         "schemas": {
@@ -168,7 +168,7 @@ You can use this same `responses` parameter to add different media types for the
 
 For example, you can add an additional media type of `image/png`, declaring that your *path operation* can return a JSON object (with media type `application/json`) or a PNG image:
 
-```Python hl_lines="19 20 21 22 23 24  28"
+```Python hl_lines="19-24  28"
 {!../../../docs_src/additional_responses/tutorial002.py!}
 ```
 
@@ -192,7 +192,7 @@ For example, you can declare a response with a status code `404` that uses a Pyd
 
 And a response with a status code `200` that uses your `response_model`, but includes a custom `example`:
 
-```Python hl_lines="20 21 22 23 24 25 26 27 28 29 30 31"
+```Python hl_lines="20-31"
 {!../../../docs_src/additional_responses/tutorial003.py!}
 ```
 
@@ -228,7 +228,7 @@ You can use that technique to re-use some predefined responses in your *path ope
 
 For example:
 
-```Python hl_lines="13 14 15 16 17 26"
+```Python hl_lines="13-17  26"
 {!../../../docs_src/additional_responses/tutorial004.py!}
 ```
 
index 523bc91bf472637046f1050bbb55995fc1de8c1e..93c288e1b4f563e687fb97f7db81794afb42df01 100644 (file)
@@ -23,7 +23,7 @@ Later, for your production application, you might want to use a database server
 * Create a `metadata` object.
 * Create a table `notes` using the `metadata` object.
 
-```Python hl_lines="4 14 16 17 18 19 20 21 22"
+```Python hl_lines="4  14  16-22"
 {!../../../docs_src/async_sql_databases/tutorial001.py!}
 ```
 
@@ -38,7 +38,7 @@ Later, for your production application, you might want to use a database server
 * Create a `DATABASE_URL`.
 * Create a `database` object.
 
-```Python hl_lines="3 9 12"
+```Python hl_lines="3  9  12"
 {!../../../docs_src/async_sql_databases/tutorial001.py!}
 ```
 
@@ -54,7 +54,7 @@ Here, this section would run directly, right before starting your **FastAPI** ap
 * Create an `engine`.
 * Create all the tables from the `metadata` object.
 
-```Python hl_lines="25 26 27 28"
+```Python hl_lines="25-28"
 {!../../../docs_src/async_sql_databases/tutorial001.py!}
 ```
 
@@ -65,7 +65,7 @@ Create Pydantic models for:
 * Notes to be created (`NoteIn`).
 * Notes to be returned (`Note`).
 
-```Python hl_lines="31 32 33 36 37 38 39"
+```Python hl_lines="31-33  36-39"
 {!../../../docs_src/async_sql_databases/tutorial001.py!}
 ```
 
@@ -78,7 +78,7 @@ So, you will be able to see it all in the interactive API docs.
 * Create your `FastAPI` application.
 * Create event handlers to connect and disconnect from the database.
 
-```Python hl_lines="42 45 46 47 50 51 52"
+```Python hl_lines="42  45-47  50-52"
 {!../../../docs_src/async_sql_databases/tutorial001.py!}
 ```
 
@@ -86,7 +86,7 @@ So, you will be able to see it all in the interactive API docs.
 
 Create the *path operation function* to read notes:
 
-```Python hl_lines="55 56 57 58"
+```Python hl_lines="55-58"
 {!../../../docs_src/async_sql_databases/tutorial001.py!}
 ```
 
@@ -103,7 +103,7 @@ That documents (and validates, serializes, filters) the output data, as a `list`
 
 Create the *path operation function* to create notes:
 
-```Python hl_lines="61 62 63 64 65"
+```Python hl_lines="61-65"
 {!../../../docs_src/async_sql_databases/tutorial001.py!}
 ```
 
index 9e7cc70a9e637d087b8207487e535bff62a3e089..921bdb708c8711fae419688b296346a9faaf215f 100644 (file)
@@ -77,7 +77,7 @@ The marker `@pytest.mark.asyncio` tells pytest that this test function should be
 
 Then we can create an `AsyncClient` with the app, and send async requests to it, using `await`.
 
-```Python hl_lines="9 10"
+```Python hl_lines="9-10"
 {!../../../docs_src/async_tests/test_main.py!}
 ```
 
index 70cd5a17014834dd539629c9fddb8f91680b2f18..766a218aa344c78aa08941417b194dd89fbf2277 100644 (file)
@@ -44,7 +44,7 @@ proxy --> server
 
 The docs UI would also need the OpenAPI schema to declare that this API `server` is located at `/api/v1` (behind the proxy). For example:
 
-```JSON hl_lines="4 5 6 7 8"
+```JSON hl_lines="4-8"
 {
     "openapi": "3.0.2",
     // More stuff here
@@ -290,13 +290,13 @@ If you pass a custom list of `servers` and there's a `root_path` (because your A
 
 For example:
 
-```Python hl_lines="4 5 6 7"
+```Python hl_lines="4-7"
 {!../../../docs_src/behind_a_proxy/tutorial003.py!}
 ```
 
 Will generate an OpenAPI schema like:
 
-```JSON hl_lines="5 6 7"
+```JSON hl_lines="5-7"
 {
     "openapi": "3.0.2",
     // More stuff here
index 6c5e97a18b003e2460b931d1cde4d2021e5355b1..bca0c7603613db3f28836d23a8b825e2e81ef30b 100644 (file)
@@ -36,7 +36,7 @@ If there's no `gzip` in the header, it will not try to decompress the body.
 
 That way, the same route class can handle gzip compressed or uncompressed requests.
 
-```Python hl_lines="8 9 10 11 12 13 14 15"
+```Python hl_lines="8-15"
 {!../../../docs_src/custom_request_and_route/tutorial001.py!}
 ```
 
@@ -50,7 +50,7 @@ This method returns a function. And that function is what will receive a request
 
 Here we use it to create a `GzipRequest` from the original request.
 
-```Python hl_lines="18 19 20 21 22 23 24 25 26"
+```Python hl_lines="18-26"
 {!../../../docs_src/custom_request_and_route/tutorial001.py!}
 ```
 
@@ -84,13 +84,13 @@ We can also use this same approach to access the request body in an exception ha
 
 All we need to do is handle the request inside a `try`/`except` block:
 
-```Python hl_lines="13 15"
+```Python hl_lines="13  15"
 {!../../../docs_src/custom_request_and_route/tutorial002.py!}
 ```
 
 If an exception occurs, the`Request` instance will still be in scope, so we can read and make use of the request body when handling the error:
 
-```Python hl_lines="16 17 18"
+```Python hl_lines="16-18"
 {!../../../docs_src/custom_request_and_route/tutorial002.py!}
 ```
 
@@ -104,6 +104,6 @@ You can also set the `route_class` parameter of an `APIRouter`:
 
 In this example, the *path operations* under the `router` will use the custom `TimedRoute` class, and will have an extra `X-Response-Time` header in the response with the time it took to generate the response:
 
-```Python hl_lines="13 14 15 16 17 18 19 20"
+```Python hl_lines="13-20"
 {!../../../docs_src/custom_request_and_route/tutorial003.py!}
 ```
index f753cc300fc7ac7e0ea285646abf060026cf20b9..e9cac6df08487b9f7870de095a07158c0142ca3c 100644 (file)
@@ -21,7 +21,7 @@ For example, if you are squeezing performance, you can install and use <a href="
 
 Import the `Response` class (sub-class) you want to use and declare it in the *path operation decorator*.
 
-```Python hl_lines="2 7"
+```Python hl_lines="2  7"
 {!../../../docs_src/custom_response/tutorial001b.py!}
 ```
 
@@ -42,7 +42,7 @@ To return a response with HTML directly from **FastAPI**, use `HTMLResponse`.
 * Import `HTMLResponse`.
 * Pass `HTMLResponse` as the parameter `content_type` of your *path operation*.
 
-```Python hl_lines="2 7"
+```Python hl_lines="2  7"
 {!../../../docs_src/custom_response/tutorial002.py!}
 ```
 
@@ -59,7 +59,7 @@ As seen in [Return a Response directly](response-directly.md){.internal-link tar
 
 The same example from above, returning an `HTMLResponse`, could look like:
 
-```Python hl_lines="2 7 19"
+```Python hl_lines="2  7  19"
 {!../../../docs_src/custom_response/tutorial003.py!}
 ```
 
@@ -79,7 +79,7 @@ The `response_class` will then be used only to document the OpenAPI *path operat
 
 For example, it could be something like:
 
-```Python hl_lines="7 23 21"
+```Python hl_lines="7  21  23"
 {!../../../docs_src/custom_response/tutorial004.py!}
 ```
 
@@ -150,7 +150,7 @@ An alternative JSON response using <a href="https://github.com/ultrajson/ultrajs
 !!! warning
     `ujson` is less careful than Python's built-in implementation in how it handles some edge-cases.
 
-```Python hl_lines="2 7"
+```Python hl_lines="2  7"
 {!../../../docs_src/custom_response/tutorial001.py!}
 ```
 
@@ -179,7 +179,7 @@ If you have a file-like object (e.g. the object returned by `open()`), you can r
 
 This includes many libraries to interact with cloud storage, video processing, and others.
 
-```Python hl_lines="2  10 11"
+```Python hl_lines="2  10-11"
 {!../../../docs_src/custom_response/tutorial008.py!}
 ```
 
@@ -211,7 +211,7 @@ The parameter that defines this is `default_response_class`.
 
 In the example below, **FastAPI** will use `ORJSONResponse` by default, in all *path operations*, instead of `JSONResponse`.
 
-```Python hl_lines="2 4"
+```Python hl_lines="2  4"
 {!../../../docs_src/custom_response/tutorial010.py!}
 ```
 
index 4985aebde9391e2b0c8fe1dfdc6b1c7b02116b10..9179126df45e4f83e3175c5dd6c5d58e05edb4f1 100644 (file)
@@ -43,7 +43,7 @@ For example, let's add <a href="https://github.com/Rebilly/ReDoc/blob/master/doc
 
 First, write all your **FastAPI** application as normally:
 
-```Python hl_lines="1 4 7 8 9"
+```Python hl_lines="1  4  7-9"
 {!../../../docs_src/extending_openapi/tutorial001.py!}
 ```
 
@@ -51,7 +51,7 @@ First, write all your **FastAPI** application as normally:
 
 Then, use the same utility function to generate the OpenAPI schema, inside a `custom_openapi()` function:
 
-```Python hl_lines="2  15 16 17 18 19 20"
+```Python hl_lines="2  15-20"
 {!../../../docs_src/extending_openapi/tutorial001.py!}
 ```
 
@@ -59,7 +59,7 @@ Then, use the same utility function to generate the OpenAPI schema, inside a `cu
 
 Now you can add the ReDoc extension, adding a custom `x-logo` to the `info` "object" in the OpenAPI schema:
 
-```Python hl_lines="21 22 23"
+```Python hl_lines="21-23"
 {!../../../docs_src/extending_openapi/tutorial001.py!}
 ```
 
@@ -71,7 +71,7 @@ That way, your application won't have to generate the schema every time a user o
 
 It will be generated only once, and then the same cached schema will be used for the next requests.
 
-```Python hl_lines="13 14  24 25"
+```Python hl_lines="13-14  24-25"
 {!../../../docs_src/extending_openapi/tutorial001.py!}
 ```
 
@@ -172,7 +172,7 @@ $ pip install aiofiles
 * Import `StaticFiles`.
 * "Mount" a `StaticFiles()` instance in a specific path.
 
-```Python hl_lines="7 11"
+```Python hl_lines="7  11"
 {!../../../docs_src/extending_openapi/tutorial002.py!}
 ```
 
@@ -224,7 +224,7 @@ You can re-use FastAPI's internal functions to create the HTML pages for the doc
 
 And similarly for ReDoc...
 
-```Python hl_lines="2 3 4 5 6   14 15 16 17 18 19 20 21 22    25 26 27   30 31 32 33 34 35 36"
+```Python hl_lines="2-6  14-22  25-27  30-36"
 {!../../../docs_src/extending_openapi/tutorial002.py!}
 ```
 
@@ -239,7 +239,7 @@ And similarly for ReDoc...
 
 Now, to be able to test that everything works, create a *path operation*:
 
-```Python hl_lines="39 40 41"
+```Python hl_lines="39-41"
 {!../../../docs_src/extending_openapi/tutorial002.py!}
 ```
 
index 152754e9a543da6f84321a2489e7971a67494184..acc1a39f26ba80aca74c48b50842631206f7380d 100644 (file)
@@ -10,7 +10,7 @@ GraphQL is implemented with Graphene, you can check <a href="https://docs.graphe
 
 Import `graphene` and define your GraphQL data:
 
-```Python hl_lines="1 6 7 8 9 10"
+```Python hl_lines="1  6-10"
 {!../../../docs_src/graphql/tutorial001.py!}
 ```
 
@@ -18,7 +18,7 @@ Import `graphene` and define your GraphQL data:
 
 Then import and add Starlette's `GraphQLApp`:
 
-```Python hl_lines="3 14"
+```Python hl_lines="3  14"
 {!../../../docs_src/graphql/tutorial001.py!}
 ```
 
index 6e28940c105440517d8e571f8a562fe535c1e84c..ed90f29be7d4764037b308ccd33948889f44d631 100644 (file)
@@ -62,7 +62,7 @@ Any incoming requests to `http` or `ws` will be redirected to the secure scheme
 
 Enforces that all incoming requests have a correctly set `Host` header, in order to guard against HTTP Host Header attacks.
 
-```Python hl_lines="2  6 7 8"
+```Python hl_lines="2  6-8"
 {!../../../docs_src/advanced_middleware/tutorial002.py!}
 ```
 
index acbd61313afe80196ae016e7e6108e3edc74fe5a..6cc5a938575d2c769451d2aea374b211486ba255 100644 (file)
@@ -19,7 +19,7 @@ You can adapt it to any other NoSQL database like:
 
 For now, don't pay attention to the rest, only the imports:
 
-```Python hl_lines="3 4 5"
+```Python hl_lines="3-5"
 {!../../../docs_src/nosql_databases/tutorial001.py!}
 ```
 
@@ -54,7 +54,7 @@ This utility function will:
     * Set defaults for timeouts.
 * Return it.
 
-```Python hl_lines="12 13 14 15 16 17 18 19 20 21"
+```Python hl_lines="12-21"
 {!../../../docs_src/nosql_databases/tutorial001.py!}
 ```
 
@@ -66,7 +66,7 @@ As **Couchbase** "documents" are actually just "JSON objects", we can model them
 
 First, let's create a `User` model:
 
-```Python hl_lines="24 25 26 27 28"
+```Python hl_lines="24-28"
 {!../../../docs_src/nosql_databases/tutorial001.py!}
 ```
 
@@ -80,7 +80,7 @@ This will have the data that is actually stored in the database.
 
 We don't create it as a subclass of Pydantic's `BaseModel` but as a subclass of our own `User`, because it will have all the attributes in `User` plus a couple more:
 
-```Python hl_lines="31 32 33"
+```Python hl_lines="31-33"
 {!../../../docs_src/nosql_databases/tutorial001.py!}
 ```
 
@@ -100,7 +100,7 @@ Now create a function that will:
 
 By creating a function that is only dedicated to getting your user from a `username` (or any other parameter) independent of your *path operation function*, you can more easily re-use it in multiple parts and also add <abbr title="Automated test, written in code, that checks if another piece of code is working correctly.">unit tests</abbr> for it:
 
-```Python hl_lines="36 37 38 39 40 41 42"
+```Python hl_lines="36-42"
 {!../../../docs_src/nosql_databases/tutorial001.py!}
 ```
 
@@ -145,7 +145,7 @@ As our code is calling Couchbase and we are not using the <a href="https://docs.
 
 Also, Couchbase recommends not using a single `Bucket` object in multiple "<abbr title="A sequence of code being executed by the program, while at the same time, or at intervals, there can be others being executed too.">thread</abbr>s", so, we can just get the bucket directly and pass it to our utility functions:
 
-```Python hl_lines="49 50 51 52 53"
+```Python hl_lines="49-53"
 {!../../../docs_src/nosql_databases/tutorial001.py!}
 ```
 
index 4c3d97e385bd1b6cd34cdafe5df94a0c5ca8dd24..e927aea4db6f8dc7437e677757d23ddd6493f712 100644 (file)
@@ -31,7 +31,7 @@ It will have a *path operation* that will receive an `Invoice` body, and a query
 
 This part is pretty normal, most of the code is probably already familiar to you:
 
-```Python hl_lines="10 11 12 13 14  37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54"
+```Python hl_lines="10-14  37-54"
 {!../../../docs_src/openapi_callbacks/tutorial001.py!}
 ```
 
@@ -92,7 +92,7 @@ Because of that, you need to declare what will be the `default_response_class`,
 
     But as we are never calling `app.include_router(some_router)`, we need to set the `default_response_class` during creation of the `APIRouter`.
 
-```Python hl_lines="5 26"
+```Python hl_lines="5  26"
 {!../../../docs_src/openapi_callbacks/tutorial001.py!}
 ```
 
@@ -105,7 +105,7 @@ It should look just like a normal FastAPI *path operation*:
 * It should probably have a declaration of the body it should receive, e.g. `body: InvoiceEvent`.
 * And it could also have a declaration of the response it should return, e.g. `response_model=InvoiceEventReceived`.
 
-```Python hl_lines="17 18 19  22 23  29 30 31 32 33"
+```Python hl_lines="17-19  22-23  29-33"
 {!../../../docs_src/openapi_callbacks/tutorial001.py!}
 ```
 
index 7a3247a64ab4da0527809bbc6fe89e97c424d933..8d085d754983545f0eba802bec7e22920a5e6d77 100644 (file)
@@ -19,7 +19,7 @@ If you want to use your APIs' function names as `operationId`s, you can iterate
 
 You should do it after adding all your *path operations*.
 
-```Python hl_lines="2 12 13 14 15 16 17 18 19 20 21 24"
+```Python hl_lines="2  12-21  24"
 {!../../../docs_src/path_operation_advanced_configuration/tutorial002.py!}
 ```
 
@@ -47,6 +47,6 @@ Adding an `\f` (an escaped "form feed" character) causes **FastAPI** to truncate
 
 It won't show up in the documentation, but other tools (such as Sphinx) will be able to use the rest.
 
-```Python hl_lines="19 20 21 22 23 24 25 26 27 28 29"
+```Python hl_lines="19-29"
 {!../../../docs_src/path_operation_advanced_configuration/tutorial004.py!}
 ```
index e46ae755f79d97f3088977106875d2b78831e404..9178ef81621dbf9c2739c8d02ac30615a4046cde 100644 (file)
@@ -6,7 +6,7 @@ You can declare a parameter of type `Response` in your *path operation function*
 
 And then you can set cookies in that *temporal* response object.
 
-```Python hl_lines="1  8 9"
+```Python hl_lines="1  8-9"
 {!../../../docs_src/response_cookies/tutorial002.py!}
 ```
 
@@ -26,7 +26,7 @@ To do that, you can create a response as described in [Return a Response Directl
 
 Then set Cookies in it, and then return it:
 
-```Python hl_lines="10 11 12"
+```Python hl_lines="10-12"
 {!../../../docs_src/response_cookies/tutorial001.py!}
 ```
 
index f0ab2831d5a9cf0b15e7895a6f2fdb7588cabbda..8836140ecf7ee2122f18cf6f8d497dd4641034bd 100644 (file)
@@ -31,7 +31,7 @@ For example, you cannot put a Pydantic model in a `JSONResponse` without first c
 
 For those cases, you can use the `jsonable_encoder` to convert your data before passing it to a response:
 
-```Python hl_lines="6 7  21 22"
+```Python hl_lines="6-7  21-22"
 {!../../../docs_src/response_directly/tutorial001.py!}
 ```
 
index 914bd44017a86dd7dac3d8cb4ca1670bcb739918..758bd64556c85f4408fbf4e392f11c53875cbb16 100644 (file)
@@ -6,7 +6,7 @@ You can declare a parameter of type `Response` in your *path operation function*
 
 And then you can set headers in that *temporal* response object.
 
-```Python hl_lines="1  7 8"
+```Python hl_lines="1  7-8"
 {!../../../docs_src/response_headers/tutorial002.py!}
 ```
 
@@ -24,7 +24,7 @@ You can also add headers when you return a `Response` directly.
 
 Create a response as described in [Return a Response Directly](response-directly.md){.internal-link target=_blank} and pass the headers as an additional parameter:
 
-```Python hl_lines="10 11 12"
+```Python hl_lines="10-12"
 {!../../../docs_src/response_headers/tutorial001.py!}
 ```
 
index c0ebea4fed9f7c074654459a31a9eba0954a2d50..6c589cd9afe32b4478aec2e2f040ba6e31d39000 100644 (file)
@@ -20,7 +20,7 @@ Then, when you type that username and password, the browser sends them in the he
 * It returns an object of type `HTTPBasicCredentials`:
     * It contains the `username` and `password` sent.
 
-```Python hl_lines="2 6 10"
+```Python hl_lines="2  6  10"
 {!../../../docs_src/security/tutorial006.py!}
 ```
 
@@ -36,7 +36,7 @@ Use a dependency to check if the username and password are correct.
 
 For this, use the Python standard module <a href="https://docs.python.org/3/library/secrets.html" class="external-link" target="_blank">`secrets`</a> to check the username and password:
 
-```Python hl_lines="1  11 12 13"
+```Python hl_lines="1  11-13"
 {!../../../docs_src/security/tutorial007.py!}
 ```
 
@@ -102,6 +102,6 @@ That way, using `secrets.compare_digest()` in your application code, it will be
 
 After detecting that the credentials are incorrect, return an `HTTPException` with a status code 401 (the same returned when no credentials are provided) and add the header `WWW-Authenticate` to make the browser show the login prompt again:
 
-```Python hl_lines="15 16 17 18 19"
+```Python hl_lines="15-19"
 {!../../../docs_src/security/tutorial007.py!}
 ```
index 5b3d57d7fa2e1e46c7aa0322b3387011ed35c3ad..c40695ba6c04431a7a5547791cffbf6468b5186f 100644 (file)
@@ -56,7 +56,7 @@ They are normally used to declare specific security permissions, for example:
 
 First, let's quickly see the parts that change from the examples in the main **Tutorial - User Guide** for [OAuth2 with Password (and hashing), Bearer with JWT tokens](../../tutorial/security/oauth2-jwt.md){.internal-link target=_blank}. Now using OAuth2 scopes:
 
-```Python hl_lines="2  4  8  12  46  64  105  107 108 109 110 111 112 113 114 115  121 122 123 124  128 129 130 131 132 133 134  139  153"
+```Python hl_lines="2  4  8  12  46  64  105  107-115  121-124  128-134  139  153"
 {!../../../docs_src/security/tutorial005.py!}
 ```
 
@@ -68,7 +68,7 @@ The first change is that now we are declaring the OAuth2 security scheme with tw
 
 The `scopes` parameter receives a `dict` with each scope as a key and the description as the value:
 
-```Python hl_lines="62 63 64 65"
+```Python hl_lines="62-65"
 {!../../../docs_src/security/tutorial005.py!}
 ```
 
@@ -159,7 +159,7 @@ We create an `HTTPException` that we can re-use (`raise`) later at several point
 
 In this exception, we include the scopes required (if any) as a string separated by spaces (using `scope_str`). We put that string containing the scopes in in the `WWW-Authenticate` header (this is part of the spec).
 
-```Python hl_lines="105  107 108 109 110 111 112 113 114 115"
+```Python hl_lines="105  107-115"
 {!../../../docs_src/security/tutorial005.py!}
 ```
 
@@ -177,7 +177,7 @@ Instead of, for example, a `dict`, or something else, as it could break the appl
 
 We also verify that we have a user with that username, and if not, we raise that same exception we created before.
 
-```Python hl_lines="46  116 117 118 119 120 121 122 123 124 125 126 127"
+```Python hl_lines="46  116-127"
 {!../../../docs_src/security/tutorial005.py!}
 ```
 
@@ -187,7 +187,7 @@ We now verify that all the scopes required, by this dependency and all the depen
 
 For this, we use `security_scopes.scopes`, that contains a `list` with all these scopes as `str`.
 
-```Python hl_lines="128 129 130 131 132 133 134"
+```Python hl_lines="128-134"
 {!../../../docs_src/security/tutorial005.py!}
 ```
 
index f30de226c7c2299156471120c2715aab2345b4b4..706a71173e76fe025032f75d2512d57cd159af1a 100644 (file)
@@ -135,7 +135,7 @@ The same way as with Pydantic models, you declare class attributes with type ann
 
 You can use all the same validation features and tools you use for Pydantic models, like different data types and additional validations with `Field()`.
 
-```Python hl_lines="2  5 6 7 8  11"
+```Python hl_lines="2  5-8  11"
 {!../../../docs_src/settings/tutorial001.py!}
 ```
 
@@ -150,7 +150,7 @@ Next it will convert and validate the data. So, when you use that `settings` obj
 
 Then you can use the new `settings` object in your application:
 
-```Python hl_lines="18 19 20"
+```Python hl_lines="18-20"
 {!../../../docs_src/settings/tutorial001.py!}
 ```
 
@@ -189,7 +189,7 @@ For example, you could have a file `config.py` with:
 
 And then use it in a file `main.py`:
 
-```Python hl_lines="3  11 12 13"
+```Python hl_lines="3  11-13"
 {!../../../docs_src/settings/app01/main.py!}
 ```
 
@@ -216,7 +216,7 @@ Notice that now we don't create a default instance `settings = Settings()`.
 
 Now we create a dependency that returns a new `config.Settings()`.
 
-```Python hl_lines="5  11 12"
+```Python hl_lines="5  11-12"
 {!../../../docs_src/settings/app02/main.py!}
 ```
 
@@ -227,7 +227,7 @@ Now we create a dependency that returns a new `config.Settings()`.
 
 And then we can require it from the *path operation function* as a dependency and use it anywhere we need it.
 
-```Python hl_lines="16  18 19 20"
+```Python hl_lines="16  18-20"
 {!../../../docs_src/settings/app02/main.py!}
 ```
 
@@ -235,7 +235,7 @@ And then we can require it from the *path operation function* as a dependency an
 
 Then it would be very easy to provide a different settings object during testing by creating a dependency override for `get_settings`:
 
-```Python hl_lines="8 9  12  21"
+```Python hl_lines="8-9  12  21"
 {!../../../docs_src/settings/app02/test_main.py!}
 ```
 
@@ -272,7 +272,7 @@ APP_NAME="ChimichangApp"
 
 And then update your `config.py` with:
 
-```Python hl_lines="9 10"
+```Python hl_lines="9-10"
 {!../../../docs_src/settings/app03/config.py!}
 ```
 
index 7610290066b019069140ec6ecbf42ca77dd70e8b..536a08fb9604a65e8667e02121563b40a22c2f12 100644 (file)
@@ -113,7 +113,7 @@ This might seem a bit complex (and it actually is), you don't really need to com
 
 We will create a `PeeweeConnectionState`:
 
-```Python hl_lines="10 11 12 13 14 15 16 17 18 19"
+```Python hl_lines="10-19"
 {!../../../docs_src/sql_databases_peewee/sql_app/database.py!}
 ```
 
@@ -161,7 +161,7 @@ This is the same you would do if you followed the Peewee tutorial and updated th
 
 Import `db` from `database` (the file `database.py` from above) and use it here.
 
-```Python hl_lines="3  6 7 8 9 10 11 12  15 16 17 18 19 20 21"
+```Python hl_lines="3  6-12  15-21"
 {!../../../docs_src/sql_databases_peewee/sql_app/models.py!}
 ```
 
@@ -189,7 +189,7 @@ Now let's check the file `sql_app/schemas.py`.
 
 Create all the same Pydantic models as in the SQLAlchemy tutorial:
 
-```Python hl_lines="16 17 18  21 22  25 26 27 28 29 30  34 35  38 39  42 43 44 45 46 47 48"
+```Python hl_lines="16-18  21-22  25-30  34-35  38-39  42-48"
 {!../../../docs_src/sql_databases_peewee/sql_app/schemas.py!}
 ```
 
@@ -214,7 +214,7 @@ But recent versions of Pydantic allow providing a custom class that inherits fro
 
 We are going to create a custom `PeeweeGetterDict` class and use it in all the same Pydantic *models* / schemas that use `orm_mode`:
 
-```Python hl_lines="3 8 9 10 11 12 13  31  49"
+```Python hl_lines="3  8-13  31  49"
 {!../../../docs_src/sql_databases_peewee/sql_app/schemas.py!}
 ```
 
@@ -235,7 +235,7 @@ Now let's see the file `sql_app/crud.py`.
 
 Create all the same CRUD utils as in the SQLAlchemy tutorial, all the code is very similar:
 
-```Python hl_lines="1  4 5  8 9  12 13  16 17 18 19 20  23 24  27 28 29 30"
+```Python hl_lines="1  4-5  8-9  12-13  16-20  23-24  27-30"
 {!../../../docs_src/sql_databases_peewee/sql_app/crud.py!}
 ```
 
@@ -259,7 +259,7 @@ And now in the file `sql_app/main.py` let's integrate and use all the other part
 
 In a very simplistic way create the database tables:
 
-```Python hl_lines="9 10 11"
+```Python hl_lines="9-11"
 {!../../../docs_src/sql_databases_peewee/sql_app/main.py!}
 ```
 
@@ -267,7 +267,7 @@ In a very simplistic way create the database tables:
 
 Create a dependency that will connect the database right at the beginning of a request and disconnect it at the end:
 
-```Python hl_lines="23 24 25 26 27 28 29"
+```Python hl_lines="23-29"
 {!../../../docs_src/sql_databases_peewee/sql_app/main.py!}
 ```
 
@@ -291,7 +291,7 @@ For all the `contextvars` parts to work, we need to make sure we have an indepen
 
 For that, we need to create another `async` dependency `reset_db_state()` that is used as a sub-dependency in `get_db()`. It will set the value for the context variable (with just a default `dict`) that will be used as the database state for the whole request. And then the dependency `get_db()` will store in it the database state (connection, transactions, etc).
 
-```Python hl_lines="18 19 20"
+```Python hl_lines="18-20"
 {!../../../docs_src/sql_databases_peewee/sql_app/main.py!}
 ```
 
@@ -310,7 +310,7 @@ If you are using a <a href="http://docs.peewee-orm.com/en/latest/peewee/database
 
 So, you would reset it with:
 
-```Python hl_lines="3 4"
+```Python hl_lines="3-4"
 async def reset_db_state():
     database.db.obj._state._state.set(db_state_default.copy())
     database.db.obj._state.reset()
@@ -320,7 +320,7 @@ async def reset_db_state():
 
 Now, finally, here's the standard **FastAPI** *path operations* code.
 
-```Python hl_lines="32 33 34 35 36 37  40 41 42 43  46 47 48 49 50 51 52 53  56 57 58 59 60 61 62  65 66 67 68  71 72 73 74 75 76 77 78 79"
+```Python hl_lines="32-37  40-43  46-53  56-62  65-68  71-79"
 {!../../../docs_src/sql_databases_peewee/sql_app/main.py!}
 ```
 
index 9ee84b32263e95b8871aa82f8f1927feda63532f..a089632acf3c250cd4efdc6db1d8ee49143f5f78 100644 (file)
@@ -10,7 +10,7 @@ If you need to have two independent FastAPI applications, with their own indepen
 
 First, create the main, top-level, **FastAPI** application, and its *path operations*:
 
-```Python hl_lines="3 6 7 8"
+```Python hl_lines="3  6-8"
 {!../../../docs_src/sub_applications/tutorial001.py!}
 ```
 
@@ -20,7 +20,7 @@ Then, create your sub-application, and its *path operations*.
 
 This sub-application is just another standard FastAPI application, but this is the one that will be "mounted":
 
-```Python hl_lines="11 14 15 16"
+```Python hl_lines="11  14-16"
 {!../../../docs_src/sub_applications/tutorial001.py!}
 ```
 
@@ -30,7 +30,7 @@ In your top-level application, `app`, mount the sub-application, `subapi`.
 
 In this case, it will be mounted at the path `/subapi`:
 
-```Python hl_lines="11 19"
+```Python hl_lines="11  19"
 {!../../../docs_src/sub_applications/tutorial001.py!}
 ```
 
index 59d2735cb7f39c2bf70019de854d2a39ac051e13..a8e2575c19a81fe19815afc0b0961f970c68462b 100644 (file)
@@ -39,7 +39,7 @@ $ pip install aiofiles
 * Declare a `Request` parameter in the *path operation* that will return a template.
 * Use the `templates` you created to render and return a `TemplateResponse`, passing the `request` as one of the key-value pairs in the Jinja2 "context".
 
-```Python hl_lines="4  11  15 16"
+```Python hl_lines="4  11  15-16"
 {!../../../docs_src/templates/tutorial001.py!}
 ```
 
index 385d988005fae014972f1235b4f27acbf435ced0..16484b09af9b1945071a58cdaa3d0670f2b5ef90 100644 (file)
@@ -26,7 +26,7 @@ We create a new file at `sql_app/tests/test_sql_app.py`.
 
 So the new file structure looks like:
 
-``` hl_lines="9 10 11"
+``` hl_lines="9-11"
 .
 └── sql_app
     ├── __init__.py
@@ -48,7 +48,7 @@ For the tests we'll use a file `test.db` instead of `sql_app.db`.
 
 But the rest of the session code is more or less the same, we just copy it.
 
-```Python hl_lines="8  9  10 11 12 13"
+```Python hl_lines="8-13"
 {!../../../docs_src/sql_databases/sql_app/tests/test_sql_app.py!}
 ```
 
@@ -77,7 +77,7 @@ So we add that line here, with the new file.
 
 Now we create the dependency override and add it to the overrides for our app.
 
-```Python hl_lines="19 20 21 22 23 24  27"
+```Python hl_lines="19-24  27"
 {!../../../docs_src/sql_databases/sql_app/tests/test_sql_app.py!}
 ```
 
@@ -88,7 +88,7 @@ Now we create the dependency override and add it to the overrides for our app.
 
 Then we can just test the app as normally.
 
-```Python hl_lines="32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47"
+```Python hl_lines="32-47"
 {!../../../docs_src/sql_databases/sql_app/tests/test_sql_app.py!}
 ```
 
index 0dc20afff9bc0492a77d91b4973b5c46c978ffba..79208e8dc8625ea6b03e44f4ebd9098e56755c56 100644 (file)
@@ -28,7 +28,7 @@ To override a dependency for testing, you put as a key the original dependency (
 
 And then **FastAPI** will call that override instead of the original dependency.
 
-```Python hl_lines="26 27 30"
+```Python hl_lines="26-27  30"
 {!../../../docs_src/dependency_testing/tutorial001.py!}
 ```
 
index 45d8d868654fbaa8c21cc188eaa30bb75bf1e528..b24a2ccfe854643af45309d6d30787a07fa248da 100644 (file)
@@ -2,6 +2,6 @@
 
 When you need your event handlers (`startup` and `shutdown`) to run in your tests, you can use the `TestClient` with a `with` statement:
 
-```Python hl_lines="9 10 11 12 20 21 22 23 24"
+```Python hl_lines="9-12  20-24"
 {!../../../docs_src/app_testing/tutorial003.py!}
 ```
index ab2c3eb1034db661482920d901200a6dd1f4feb0..4101e5a16b70a411ce5d8eb9274d41aacd90b1eb 100644 (file)
@@ -4,7 +4,7 @@ You can use the same `TestClient` to test WebSockets.
 
 For this, you use the `TestClient` in a `with` statement, connecting to the WebSocket:
 
-```Python hl_lines="27 28 29 30 31"
+```Python hl_lines="27-31"
 {!../../../docs_src/app_testing/tutorial002.py!}
 ```
 
index ac452c25ee343d8374b762be4466cb975779a08d..500afa34b289e2da5e6d78e97feeed3d00b57358 100644 (file)
@@ -29,7 +29,7 @@ Let's imagine you want to get the client's IP address/host inside of your *path
 
 For that you need to access the request directly.
 
-```Python hl_lines="1  7 8"
+```Python hl_lines="1  7-8"
 {!../../../docs_src/using_request_directly/tutorial001.py!}
 ```
 
index 1fe32bc6140488b1771b19da51083834b7147b73..878ad37ddc31b34e0983b2ef57a66ca43a5dc92f 100644 (file)
@@ -24,7 +24,7 @@ In production you would have one of the options above.
 
 But it's the simplest way to focus on the server-side of WebSockets and have a working example:
 
-```Python hl_lines="2  6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38  41 42 43"
+```Python hl_lines="2  6-38  41-43"
 {!../../../docs_src/websockets/tutorial001.py!}
 ```
 
@@ -32,7 +32,7 @@ But it's the simplest way to focus on the server-side of WebSockets and have a w
 
 In your **FastAPI** application, create a `websocket`:
 
-```Python hl_lines="1 46 47"
+```Python hl_lines="1  46-47"
 {!../../../docs_src/websockets/tutorial001.py!}
 ```
 
@@ -45,7 +45,7 @@ In your **FastAPI** application, create a `websocket`:
 
 In your WebSocket route you can `await` for messages and send messages.
 
-```Python hl_lines="48 49 50 51 52"
+```Python hl_lines="48-52"
 {!../../../docs_src/websockets/tutorial001.py!}
 ```
 
@@ -98,7 +98,7 @@ In WebSocket endpoints you can import from `fastapi` and use:
 
 They work the same way as for other FastAPI endpoints/*path operations*:
 
-```Python hl_lines="58 59 60 61 62 63 64 65  68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83"
+```Python hl_lines="58-65  68-83"
 {!../../../docs_src/websockets/tutorial002.py!}
 ```
 
index 47b22d167ee581f7cef7010383a607f126dc76d9..df8865961721d9f8de3b2111dcc3df5545f4136a 100644 (file)
@@ -12,7 +12,7 @@ Then wrap the WSGI (e.g. Flask) app with the middleware.
 
 And then mount that under a path.
 
-```Python hl_lines="2 3  22"
+```Python hl_lines="2-3  22"
 {!../../../docs_src/wsgi/tutorial001.py!}
 ```
 
index 756909e989c7f4955f1b1a4f6d45b755919ce554..ac21b3eed284c6a94220f784c0de4da431d2e6c6 100644 (file)
@@ -305,7 +305,7 @@ burgers = get_burgers(2)
 
 So, if you are using a library that tells you that you can call it with `await`, you need to create the *path operation functions* that uses it with `async def`, like in:
 
-```Python hl_lines="2 3"
+```Python hl_lines="2-3"
 @app.get('/burgers')
 async def read_burgers():
     burgers = await get_burgers(2)
index 9fed5de828091e0aedc9df67a8eb21f26fbfdf97..d0b73f9fc23711ccd166d1dd931e9da050106fa0 100644 (file)
@@ -153,7 +153,7 @@ def read_item(item_id: int, q: Optional[str] = None):
 
 If your code uses `async` / `await`, use `async def`:
 
-```Python hl_lines="9 14"
+```Python hl_lines="9  14"
 from typing import Optional
 
 from fastapi import FastAPI
@@ -245,7 +245,7 @@ Now modify the file `main.py` to receive a body from a `PUT` request.
 
 Declare the body using standard Python types, thanks to Pydantic.
 
-```Python hl_lines="4  9 10 11 12  25 26 27"
+```Python hl_lines="4  9-12  25-27"
 from typing import Optional
 
 from fastapi import FastAPI
index b0dd05468579ed1c7470afa2267f929f8aa3da0f..d938de666996e230dde1b1b3e20d03186e31b186 100644 (file)
@@ -193,7 +193,7 @@ And still, the editor knows it is a `str`, and provides support for that.
 
 You would do the same to declare `tuple`s and `set`s:
 
-```Python hl_lines="1 4"
+```Python hl_lines="1  4"
 {!../../../docs_src/python_types/tutorial007.py!}
 ```
 
@@ -210,7 +210,7 @@ The first type parameter is for the keys of the `dict`.
 
 The second type parameter is for the values of the `dict`:
 
-```Python hl_lines="1 4"
+```Python hl_lines="1  4"
 {!../../../docs_src/python_types/tutorial008.py!}
 ```
 
@@ -224,7 +224,7 @@ This means:
 
 You can also use `Optional` to declare that a variable has a type, like `str`, but that it is "optional", which means that it could also be `None`:
 
-```Python hl_lines="1 4"
+```Python hl_lines="1  4"
 {!../../../docs_src/python_types/tutorial009.py!}
 ```
 
@@ -249,7 +249,7 @@ You can also declare a class as the type of a variable.
 
 Let's say you have a class `Person`, with a name:
 
-```Python hl_lines="1 2 3"
+```Python hl_lines="1-3"
 {!../../../docs_src/python_types/tutorial010.py!}
 ```
 
index a12362ebdbe0b57772bb1dcf2e10da80f395ceab..107fe60c7b3ea7a5ad77a51ba852d311ea14e712 100644 (file)
@@ -15,7 +15,7 @@ This includes, for example:
 
 First, import `BackgroundTasks` and define a parameter in your *path operation function* with a type declaration of `BackgroundTasks`:
 
-```Python hl_lines="1 13"
+```Python hl_lines="1  13"
 {!../../../docs_src/background_tasks/tutorial001.py!}
 ```
 
@@ -33,7 +33,7 @@ In this case, the task function will write to a file (simulating sending an emai
 
 And as the write operation doesn't use `async` and `await`, we define the function with normal `def`:
 
-```Python hl_lines="6 7 8 9"
+```Python hl_lines="6-9"
 {!../../../docs_src/background_tasks/tutorial001.py!}
 ```
 
@@ -57,7 +57,7 @@ Using `BackgroundTasks` also works with the dependency injection system, you can
 
 **FastAPI** knows what to do in each case and how to re-use the same object, so that all the background tasks are merged together and are run in the background afterwards:
 
-```Python hl_lines="13 15 22 25"
+```Python hl_lines="13  15  22  25"
 {!../../../docs_src/background_tasks/tutorial002.py!}
 ```
 
index 0d3be0f16538c2d18e12050c8ddfbade8d166f49..65446f5ae9d470309ce3b8af9562857652462b82 100644 (file)
@@ -60,7 +60,7 @@ You can create the *path operations* for that module using `APIRouter`.
 
 You import it and create an "instance" the same way you would with the class `FastAPI`:
 
-```Python hl_lines="1 3"
+```Python hl_lines="1  3"
 {!../../../docs_src/bigger_applications/app/routers/users.py!}
 ```
 
@@ -70,7 +70,7 @@ And then you use it to declare your *path operations*.
 
 Use it the same way you would use the `FastAPI` class:
 
-```Python hl_lines="6 11 16"
+```Python hl_lines="6  11  16"
 {!../../../docs_src/bigger_applications/app/routers/users.py!}
 ```
 
@@ -100,7 +100,7 @@ But let's say that this time we are more lazy.
 
 And we don't want to have to explicitly type `/items/` and `tags=["items"]` in every *path operation* (we will be able to do it later):
 
-```Python hl_lines="6 11"
+```Python hl_lines="6  11"
 {!../../../docs_src/bigger_applications/app/routers/items.py!}
 ```
 
@@ -110,7 +110,7 @@ We are not adding the prefix `/items/` nor the `tags=["items"]` to add them late
 
 But we can add custom `tags` and `responses` that will be applied to a specific *path operation*:
 
-```Python hl_lines="18 19"
+```Python hl_lines="18-19"
 {!../../../docs_src/bigger_applications/app/routers/items.py!}
 ```
 
@@ -126,7 +126,7 @@ This will be the main file in your application that ties everything together.
 
 You import and create a `FastAPI` class as normally:
 
-```Python hl_lines="1 5"
+```Python hl_lines="1  5"
 {!../../../docs_src/bigger_applications/app/main.py!}
 ```
 
@@ -245,7 +245,7 @@ And we can add predefined `responses` that will be included in all the *path ope
 
 And we can add a list of `dependencies` that will be added to all the *path operations* in the router and will be executed/solved for each request made to them. Note that, much like dependencies in *path operation decorators*, no value will be passed to your *path operation function*.
 
-```Python hl_lines="8 9 10 14 15 16 17 18 19 20"
+```Python hl_lines="8-10  14-20"
 {!../../../docs_src/bigger_applications/app/main.py!}
 ```
 
index 444b90145044f24dfd48cd800ab8a5ef1493ea55..6b3fd8fb571a6fdeaf3546dc518066d9da7c6e1c 100644 (file)
@@ -17,7 +17,7 @@ First, you have to import it:
 
 You can then use `Field` with model attributes:
 
-```Python hl_lines="11 12 13 14"
+```Python hl_lines="11-14"
 {!../../../docs_src/body_fields/tutorial001.py!}
 ```
 
index 48883e4cdacfe3fad99c76c57dafd3f1542327d4..1bc8f1436653288b9443ba6610b7939d6bff1ccf 100644 (file)
@@ -8,7 +8,7 @@ First, of course, you can mix `Path`, `Query` and request body parameter declara
 
 And you can also declare body parameters as optional, by setting the default to `None`:
 
-```Python hl_lines="19 20 21"
+```Python hl_lines="19-21"
 {!../../../docs_src/body_multiple_params/tutorial001.py!}
 ```
 
index 987de42a84dbb0ebe81e918013211703b0fd4b8f..14e725a213680064fc4cfa3f315517b82831673c 100644 (file)
@@ -55,7 +55,7 @@ And Python has a special data type for sets of unique items, the `set`.
 
 Then we can import `Set` and declare `tags` as a `set` of `str`:
 
-```Python hl_lines="1 14"
+```Python hl_lines="1  14"
 {!../../../docs_src/body_nested_models/tutorial003.py!}
 ```
 
@@ -79,7 +79,7 @@ All that, arbitrarily nested.
 
 For example, we can define an `Image` model:
 
-```Python hl_lines="9 10 11"
+```Python hl_lines="9-11"
 {!../../../docs_src/body_nested_models/tutorial004.py!}
 ```
 
@@ -122,7 +122,7 @@ To see all the options you have, checkout the docs for <a href="https://pydantic
 
 For example, as in the `Image` model we have a `url` field, we can declare it to be instead of a `str`, a Pydantic's `HttpUrl`:
 
-```Python hl_lines="4 10"
+```Python hl_lines="4  10"
 {!../../../docs_src/body_nested_models/tutorial005.py!}
 ```
 
@@ -169,7 +169,7 @@ This will expect (convert, validate, document, etc) a JSON body like:
 
 You can define arbitrarily deeply nested models:
 
-```Python hl_lines="9 14 20 23 27"
+```Python hl_lines="9  14  20  23  27"
 {!../../../docs_src/body_nested_models/tutorial007.py!}
 ```
 
index 01620d88f7d4f7557753bc914bb9e992fbae3359..757d7bdbcfd6c127b1286a5147935480a2011fda 100644 (file)
@@ -6,7 +6,7 @@ To update an item you can use the <a href="https://developer.mozilla.org/en-US/d
 
 You can use the `jsonable_encoder` to convert the input data to data that can be stored as JSON (e.g. with a NoSQL database). For example, converting `datetime` to `str`.
 
-```Python hl_lines="30 31 32 33 34 35"
+```Python hl_lines="30-35"
 {!../../../docs_src/body_updates/tutorial001.py!}
 ```
 
@@ -82,7 +82,7 @@ In summary, to apply partial updates you would:
 * Save the data to your DB.
 * Return the updated model.
 
-```Python hl_lines="30 31 32 33 34 35 36 37"
+```Python hl_lines="30-37"
 {!../../../docs_src/body_updates/tutorial002.py!}
 ```
 
index f5a75dfe055c0c35c2c10eaf96b46ee6518bd06a..2afc979989058a174b54d856aa64beb59af215eb 100644 (file)
@@ -29,7 +29,7 @@ Then you declare your data model as a class that inherits from `BaseModel`.
 
 Use standard Python types for all the attributes:
 
-```Python hl_lines="7 8 9 10 11"
+```Python hl_lines="7-11"
 {!../../../docs_src/body/tutorial001.py!}
 ```
 
@@ -135,7 +135,7 @@ You can declare path parameters and body requests at the same time.
 
 **FastAPI** will recognize that the function parameters that match path parameters should be **taken from the path**, and that function parameters that are declared to be Pydantic models should be **taken from the request body**.
 
-```Python hl_lines="17 18"
+```Python hl_lines="17-18"
 {!../../../docs_src/body/tutorial003.py!}
 ```
 
index 31da532e466a18d517428a9bdf07e7c5271030c6..6a694995a181acbc29003b7f714d41c0d9db02da 100644 (file)
@@ -46,7 +46,7 @@ You can also specify if your backend allows:
 * Specific HTTP methods (`POST`, `PUT`) or all of them with the wildcard `"*"`.
 * Specific HTTP headers or all of them with the wildcard `"*"`.
 
-```Python hl_lines="2  6 7 8 9 10 11  13 14 15 16 17 18 19"
+```Python hl_lines="2  6-11  13-19"
 {!../../../docs_src/cors/tutorial001.py!}
 ```
 
index 22893073bbe664616d9bed5cdbb1664b699bf739..bda889c45c1c538fef568729b6ea2ee81b98ac22 100644 (file)
@@ -6,7 +6,7 @@ You can connect the debugger in your editor, for example with Visual Studio Code
 
 In your FastAPI application, import and run `uvicorn` directly:
 
-```Python hl_lines="1 15"
+```Python hl_lines="1  15"
 {!../../../docs_src/debugging/tutorial001.py!}
 ```
 
index 976db38c7c6fa363b6a381d6d15fd4e9c6973aa0..8c00374bf9409f208721f51dac2cfc4b0b300666 100644 (file)
@@ -71,7 +71,7 @@ That also applies to callables with no parameters at all. The same as it would b
 
 Then, we can change the dependency "dependable" `common_parameters` from above to the class `CommonQueryParams`:
 
-```Python hl_lines="11 12 13 14 15"
+```Python hl_lines="11-15"
 {!../../../docs_src/dependencies/tutorial002.py!}
 ```
 
index 3498ab3d8a2f521b84936905e8817ca256a7154b..a52dbdfbe3439c33369174cb0ef7479257126da5 100644 (file)
@@ -35,7 +35,7 @@ You can use the same dependency *functions* you use normally.
 
 They can declare request requirements (like headers) or other sub-dependencies:
 
-```Python hl_lines="6 11"
+```Python hl_lines="6  11"
 {!../../../docs_src/dependencies/tutorial006.py!}
 ```
 
@@ -43,7 +43,7 @@ They can declare request requirements (like headers) or other sub-dependencies:
 
 These dependencies can `raise` exceptions, the same as normal dependencies:
 
-```Python hl_lines="8 13"
+```Python hl_lines="8  13"
 {!../../../docs_src/dependencies/tutorial006.py!}
 ```
 
@@ -53,7 +53,7 @@ And they can return values or not, the values won't be used.
 
 So, you can re-use a normal dependency (that returns a value) you already use somewhere else, and even though the value won't be used, the dependency will be executed:
 
-```Python hl_lines="9 14"
+```Python hl_lines="9  14"
 {!../../../docs_src/dependencies/tutorial006.py!}
 ```
 
index 1c8cdba65a2a1e54840fa6e919f35aaac0999581..3388a0828c193bd8459856640dfb569d8a2d1595 100644 (file)
@@ -32,7 +32,7 @@ For example, you could use this to create a database session and close it after
 
 Only the code prior to and including the `yield` statement is executed before sending a response:
 
-```Python hl_lines="2 3 4"
+```Python hl_lines="2-4"
 {!../../../docs_src/dependencies/tutorial007.py!}
 ```
 
@@ -44,7 +44,7 @@ The yielded value is what is injected into *path operations* and other dependenc
 
 The code following the `yield` statement is executed after the response has been delivered:
 
-```Python hl_lines="5 6"
+```Python hl_lines="5-6"
 {!../../../docs_src/dependencies/tutorial007.py!}
 ```
 
@@ -63,7 +63,7 @@ So, you can look for that specific exception inside the dependency with `except
 
 In the same way, you can use `finally` to make sure the exit steps are executed, no matter if there was an exception or not.
 
-```Python hl_lines="3 5"
+```Python hl_lines="3  5"
 {!../../../docs_src/dependencies/tutorial007.py!}
 ```
 
@@ -75,7 +75,7 @@ You can have sub-dependencies and "trees" of sub-dependencies of any size and sh
 
 For example, `dependency_c` can have a dependency on `dependency_b`, and `dependency_b` on `dependency_a`:
 
-```Python hl_lines="4 12 20"
+```Python hl_lines="4  12  20"
 {!../../../docs_src/dependencies/tutorial008.py!}
 ```
 
@@ -85,7 +85,7 @@ In this case `dependency_c`, to execute its exit code, needs the value from `dep
 
 And, in turn, `dependency_b` needs the value from `dependency_a` (here named `dep_a`) to be available for its exit code.
 
-```Python hl_lines="16 17 24 25"
+```Python hl_lines="16-17  24-25"
 {!../../../docs_src/dependencies/tutorial008.py!}
 ```
 
@@ -207,7 +207,7 @@ In Python, you can create Context Managers by <a href="https://docs.python.org/3
 You can also use them inside of **FastAPI** dependencies with `yield` by using
 `with` or `async with` statements inside of the dependency function:
 
-```Python hl_lines="1 2 3 4 5 6 7 8 9 13"
+```Python hl_lines="1-9  13"
 {!../../../docs_src/dependencies/tutorial010.py!}
 ```
 
index 7adbd037291a919d5c236122db9c9c681b93797c..cf0b5a92fa0832c1b99b86acd3e9dbf3e7515d25 100644 (file)
@@ -31,7 +31,7 @@ Let's first focus on the dependency.
 
 It is just a function that can take all the same parameters that a *path operation function* can take:
 
-```Python hl_lines="8 9"
+```Python hl_lines="8-9"
 {!../../../docs_src/dependencies/tutorial001.py!}
 ```
 
index c86c91fd55aaf1952e3b718e24c33f21f219bdc2..097edb68b1d682af2d9a0c353f7366234a6c2e3a 100644 (file)
@@ -10,7 +10,7 @@ They can be as **deep** as you need them to be.
 
 You could create a first dependency ("dependable") like:
 
-```Python hl_lines="8 9"
+```Python hl_lines="8-9"
 {!../../../docs_src/dependencies/tutorial005.py!}
 ```
 
index d1d59c43ce706ec6bbcbf5b75d047a71a01bb82d..a2cbe45d5533a5482418bd0c65c84095c7a886cf 100644 (file)
@@ -20,7 +20,7 @@ You can use `jsonable_encoder` for that.
 
 It receives an object, like a Pydantic model, and returns a JSON compatible version:
 
-```Python hl_lines="5 22"
+```Python hl_lines="5  22"
 {!../../../docs_src/encoder/tutorial001.py!}
 ```
 
index 649a3cca84f0cc855511e5628b47b3aeff4aa3f2..995f0b972f9ebcdf19843398eadc19f403fe5761 100644 (file)
@@ -55,12 +55,12 @@ Here are some of the additional data types you can use:
 
 Here's an example *path operation* with parameters using some of the above types.
 
-```Python hl_lines="1  3  12 13 14 15 16"
+```Python hl_lines="1  3  12-16"
 {!../../../docs_src/extra_data_types/tutorial001.py!}
 ```
 
 Note that the parameters inside the function have their natural data type, and you can, for example, perform normal date manipulations, like:
 
-```Python hl_lines="18 19"
+```Python hl_lines="18-19"
 {!../../../docs_src/extra_data_types/tutorial001.py!}
 ```
index 70f7aff4bb8377220a8645869cb2d20c794296d5..4eced04ca98b91ef7a1633bb15dc7cf615ca6a61 100644 (file)
@@ -17,7 +17,7 @@ This is especially the case for user models, because:
 
 Here's a general idea of how the models could look like with their password fields and the places where they are used:
 
-```Python hl_lines="9 11 16 22 24  29 30  33 34 35  40 41"
+```Python hl_lines="9  11  16  22  24  29-30  33-35  40-41"
 {!../../../docs_src/extra_models/tutorial001.py!}
 ```
 
@@ -150,7 +150,7 @@ All the data conversion, validation, documentation, etc. will still work as norm
 
 That way, we can declare just the differences between the models (with plaintext `password`, with `hashed_password` and without password):
 
-```Python hl_lines="9  15 16  19 20  23 24"
+```Python hl_lines="9  15-16  19-20  23-24"
 {!../../../docs_src/extra_models/tutorial002.py!}
 ```
 
@@ -165,7 +165,7 @@ To do that, use the standard Python type hint <a href="https://docs.python.org/3
 !!! note
     When defining a <a href="https://pydantic-docs.helpmanual.io/usage/types/#unions" class="external-link" target="_blank">`Union`</a>, include the most specific type first, followed by the less specific type. In the example below, the more specific `PlaneItem` comes before `CarItem` in `Union[PlaneItem, CarItem]`.
 
-```Python hl_lines="1 14 15 18 19 20 33"
+```Python hl_lines="1  14-15  18-20  33"
 {!../../../docs_src/extra_models/tutorial003.py!}
 ```
 
@@ -175,7 +175,7 @@ The same way, you can declare responses of lists of objects.
 
 For that, use the standard Python `typing.List`:
 
-```Python hl_lines="1 20"
+```Python hl_lines="1  20"
 {!../../../docs_src/extra_models/tutorial004.py!}
 ```
 
@@ -187,7 +187,7 @@ This is useful if you don't know the valid field/attribute names (that would be
 
 In this case, you can use `typing.Dict`:
 
-```Python hl_lines="1 8"
+```Python hl_lines="1  8"
 {!../../../docs_src/extra_models/tutorial005.py!}
 ```
 
index 714c4c94a57ad28b96459a6d5f5cf126269874a9..9ea2f2ad840bea45146c13d7370c28835c9d53d9 100644 (file)
@@ -92,7 +92,7 @@ And you want to handle this exception globally with FastAPI.
 
 You could add a custom exception handler with `@app.exception_handler()`:
 
-```Python hl_lines="5 6 7  13 14 15 16 17 18  24"
+```Python hl_lines="5-7  13-18  24"
 {!../../../docs_src/handling_errors/tutorial003.py!}
 ```
 
@@ -129,7 +129,7 @@ To override it, import the `RequestValidationError` and use it with `@app.except
 
 The exception handler will receive a `Request` and the exception.
 
-```Python hl_lines="2 14 15 16"
+```Python hl_lines="2  14-16"
 {!../../../docs_src/handling_errors/tutorial004.py!}
 ```
 
@@ -179,7 +179,7 @@ The same way, you can override the `HTTPException` handler.
 
 For example, you could want to return a plain text response instead of JSON for these errors:
 
-```Python hl_lines="3 4  9 10 11 22"
+```Python hl_lines="3-4  9-11  22"
 {!../../../docs_src/handling_errors/tutorial004.py!}
 ```
 
@@ -209,7 +209,7 @@ Now try sending an invalid item like:
 
 You will receive a response telling you that the data is invalid containing the received body:
 
-```JSON hl_lines="12 13 14 15"
+```JSON hl_lines="12-15"
 {
   "detail": [
     {
@@ -256,7 +256,7 @@ You could also just want to use the exception somehow, but then use the same def
 
 You can import and re-use the default exception handlers from `fastapi.exception_handlers`:
 
-```Python hl_lines="2 3 4 5 15 21"
+```Python hl_lines="2-5  15  21"
 {!../../../docs_src/handling_errors/tutorial006.py!}
 ```
 
index 25c00db7052ff06a03c843713a2b5cd168fa9fe8..7ec3054218a161c183292868e72e40a4cd5fc159 100644 (file)
@@ -13,7 +13,7 @@ You can set the:
 
 To set them, use the parameters `title`, `description`, and `version`:
 
-```Python hl_lines="4 5 6"
+```Python hl_lines="4-6"
 {!../../../docs_src/metadata/tutorial001.py!}
 ```
 
@@ -41,7 +41,7 @@ Let's try that in an example with tags for `users` and `items`.
 
 Create metadata for your tags and pass it to the `openapi_tags` parameter:
 
-```Python hl_lines="3 4 5 6 7 8 9 10 11 12 13 14 15 16  18"
+```Python hl_lines="3-16  18"
 {!../../../docs_src/metadata/tutorial004.py!}
 ```
 
index 6f7ca000addf99397f043c846753d7a54e359619..3c6868fe4de736a3e7b00b3162ed4f263fdcb3b8 100644 (file)
@@ -28,7 +28,7 @@ The middleware function receives:
     * Then it returns the `response` generated by the corresponding *path operation*.
 * You can then modify further the `response` before returning it.
 
-```Python hl_lines="8 9  11  14"
+```Python hl_lines="8-9  11  14"
 {!../../../docs_src/middleware/tutorial001.py!}
 ```
 
@@ -50,7 +50,7 @@ And also after the `response` is generated, before returning it.
 
 For example, you could add a custom header `X-Process-Time` containing the time in seconds that it took to process the request and generate a response:
 
-```Python hl_lines="10  12  13"
+```Python hl_lines="10  12-13"
 {!../../../docs_src/middleware/tutorial001.py!}
 ```
 
index c2c30089441572e7034f9962291aa6f56315f120..0d606331db2f999b747d36d52eb048e69ef73bed 100644 (file)
@@ -28,7 +28,7 @@ That status code will be used in the response and will be added to the OpenAPI s
 
 You can add tags to your *path operation*, pass the parameter `tags` with a `list` of `str` (commonly just one `str`):
 
-```Python hl_lines="17 22 27"
+```Python hl_lines="17  22  27"
 {!../../../docs_src/path_operation_configuration/tutorial002.py!}
 ```
 
@@ -40,7 +40,7 @@ They will be added to the OpenAPI schema and used by the automatic documentation
 
 You can add a `summary` and `description`:
 
-```Python hl_lines="20 21"
+```Python hl_lines="20-21"
 {!../../../docs_src/path_operation_configuration/tutorial003.py!}
 ```
 
@@ -50,7 +50,7 @@ As descriptions tend to be long and cover multiple lines, you can declare the *p
 
 You can write <a href="https://en.wikipedia.org/wiki/Markdown" class="external-link" target="_blank">Markdown</a> in the docstring, it will be interpreted and displayed correctly (taking into account docstring indentation).
 
-```Python hl_lines="19 20 21 22 23 24 25 26 27"
+```Python hl_lines="19-27"
 {!../../../docs_src/path_operation_configuration/tutorial004.py!}
 ```
 
index 77c5c02e2fb5dc6003c98f25b0884e019b1bc055..4f59069fd28cafde12009c1ea0c5780dd43dedc3 100644 (file)
@@ -2,7 +2,7 @@
 
 You can declare path "parameters" or "variables" with the same syntax used by Python format strings:
 
-```Python hl_lines="6 7"
+```Python hl_lines="6-7"
 {!../../../docs_src/path_params/tutorial001.py!}
 ```
 
@@ -109,7 +109,7 @@ 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"
+```Python hl_lines="6  11"
 {!../../../docs_src/path_params/tutorial003.py!}
 ```
 
@@ -127,7 +127,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 7 8 9"
+```Python hl_lines="1  6-9"
 {!../../../docs_src/path_params/tutorial005.py!}
 ```
 
index d5dec36def3248985a00beba31334759159cdb4a..f741b99a00d35b93a23224d3a3cfb7b34914e518 100644 (file)
@@ -126,7 +126,7 @@ And you don't have to declare them in any specific order.
 
 They will be detected by name:
 
-```Python hl_lines="8 10"
+```Python hl_lines="8  10"
 {!../../../docs_src/query_params/tutorial004.py!}
 ```
 
@@ -138,7 +138,7 @@ If you don't want to add a specific value but just make it optional, set the def
 
 But when you want to make a query parameter required, you can just not declare any default value:
 
-```Python hl_lines="6 7"
+```Python hl_lines="6-7"
 {!../../../docs_src/query_params/tutorial005.py!}
 ```
 
index 260a5e1905aebf63617857e1a3fdce70a7e674d3..3bdf8d0022bdd495b6dd6e5b911171a88a48be59 100644 (file)
@@ -121,7 +121,7 @@ They would be associated to the same "form field" sent using "form data".
 
 To use that, declare a `List` of `bytes` or `UploadFile`:
 
-```Python hl_lines="10 15"
+```Python hl_lines="10  15"
 {!../../../docs_src/request_files/tutorial002.py!}
 ```
 
index b7201ee77d723235e5faadcf8c69caa4796b9475..fdf6611348a5387592ea3e76b07580ca373c3b7b 100644 (file)
@@ -35,13 +35,13 @@ But most importantly:
 
 Here we are declaring a `UserIn` model, it will contain a plaintext password:
 
-```Python hl_lines="9 11"
+```Python hl_lines="9  11"
 {!../../../docs_src/response_model/tutorial002.py!}
 ```
 
 And we are using this model to declare our input and the same model to declare our output:
 
-```Python hl_lines="17 18"
+```Python hl_lines="17-18"
 {!../../../docs_src/response_model/tutorial002.py!}
 ```
 
@@ -58,7 +58,7 @@ But if we use the same model for another *path operation*, we could be sending o
 
 We can instead create an input model with the plaintext password and an output model without it:
 
-```Python hl_lines="9 11 16"
+```Python hl_lines="9  11  16"
 {!../../../docs_src/response_model/tutorial003.py!}
 ```
 
@@ -90,7 +90,7 @@ And both models will be used for the interactive API documentation:
 
 Your response model could have default values, like:
 
-```Python hl_lines="11 13 14"
+```Python hl_lines="11  13-14"
 {!../../../docs_src/response_model/tutorial004.py!}
 ```
 
@@ -136,7 +136,7 @@ So, if you send a request to that *path operation* for the item with ID `foo`, t
 
 But if your data has values for the model's fields with default values, like the item with ID `bar`:
 
-```Python hl_lines="3 5"
+```Python hl_lines="3  5"
 {
     "name": "Bar",
     "description": "The bartenders",
@@ -151,7 +151,7 @@ they will be included in the response.
 
 If the data has the same values as the default ones, like the item with ID `baz`:
 
-```Python hl_lines="3 6"
+```Python hl_lines="3  5-6"
 {
     "name": "Baz",
     "description": None,
@@ -185,7 +185,7 @@ This can be used as a quick shortcut if you have only one Pydantic model and wan
 
     This also applies to `response_model_by_alias` that works similarly.
 
-```Python hl_lines="31 37"
+```Python hl_lines="31  37"
 {!../../../docs_src/response_model/tutorial005.py!}
 ```
 
@@ -198,7 +198,7 @@ This can be used as a quick shortcut if you have only one Pydantic model and wan
 
 If you forget to use a `set` and use a `list` or `tuple` instead, FastAPI will still convert it to a `set` and it will work correctly:
 
-```Python hl_lines="31 37"
+```Python hl_lines="31  37"
 {!../../../docs_src/response_model/tutorial006.py!}
 ```
 
index 7915624fa67eeaa2c98a9bce2f63b8230ac1c1ca..646378aa105ac3e6e174f17b3b13479c347e8b04 100644 (file)
@@ -71,7 +71,7 @@ But you don't have to memorize what each of these codes mean.
 
 You can use the convenience variables from `fastapi.status`.
 
-```Python hl_lines="1 6"
+```Python hl_lines="1  6"
 {!../../../docs_src/response_status_code/tutorial002.py!}
 ```
 
index d0f1b843e57ee05f9b53ebcaa7c9e7af9bcbc765..d1f9bfec44de3d044911df64558a9bcf14df3c9b 100644 (file)
@@ -10,7 +10,7 @@ There are several ways you can declare extra JSON Schema information.
 
 You can declare an example for a Pydantic model using `Config` and `schema_extra`, as described in <a href="https://pydantic-docs.helpmanual.io/usage/schema/#schema-customization" class="external-link" target="_blank">Pydantic's docs: Schema customization</a>:
 
-```Python hl_lines="15 16 17 18 19 20 21 22 23"
+```Python hl_lines="15-23"
 {!../../../docs_src/schema_extra_example/tutorial001.py!}
 ```
 
@@ -20,7 +20,7 @@ That extra info will be added as-is to the output JSON Schema.
 
 In `Field`, `Path`, `Query`, `Body` and others you'll see later, you can also declare extra info for the JSON Schema by passing any other arbitrary arguments to the function, for example, to add an `example`:
 
-```Python hl_lines="4 10 11 12 13"
+```Python hl_lines="4  10-13"
 {!../../../docs_src/schema_extra_example/tutorial002.py!}
 ```
 
@@ -33,7 +33,7 @@ The same way you can pass extra info to `Field`, you can do the same with `Path`
 
 For example, you can pass an `example` for a body request to `Body`:
 
-```Python hl_lines="21 22 23 24 25 26"
+```Python hl_lines="21-26"
 {!../../../docs_src/schema_extra_example/tutorial003.py!}
 ```
 
index 3fc0164c3263fea5ddbc4639372e5ba9865241d1..f50b69acf02281b6bd0975a8ea9ada8c44be493c 100644 (file)
@@ -16,7 +16,7 @@ First, let's create a Pydantic user model.
 
 The same way we use Pydantic to declare bodies, we can use it anywhere else:
 
-```Python hl_lines="5 12 13 14 15 16"
+```Python hl_lines="5  12-16"
 {!../../../docs_src/security/tutorial002.py!}
 ```
 
@@ -38,7 +38,7 @@ The same as we were doing before in the *path operation* directly, our new depen
 
 `get_current_user` will use a (fake) utility function we created, that takes a token as a `str` and returns our Pydantic `User` model:
 
-```Python hl_lines="19 20 21 22 26 27"
+```Python hl_lines="19-22  26-27"
 {!../../../docs_src/security/tutorial002.py!}
 ```
 
@@ -98,7 +98,7 @@ And all of them (or any portion of them that you want) can take the advantage of
 
 And all these thousands of *path operations* can be as small as 3 lines:
 
-```Python hl_lines="30 31 32"
+```Python hl_lines="30-32"
 {!../../../docs_src/security/tutorial002.py!}
 ```
 
index b65a9f58c28b297decc56728da995b66ab877d51..47b0d75d04d108d0bb52c29d686a863e40c36dda 100644 (file)
@@ -109,7 +109,7 @@ And another utility to verify if a received password matches the hash stored.
 
 And another one to authenticate and return a user.
 
-```Python hl_lines="7  48  55 56  59 60  69 70 71 72 73 74 75"
+```Python hl_lines="7  48  55-56  59-60  69-75"
 {!../../../docs_src/security/tutorial004.py!}
 ```
 
@@ -144,7 +144,7 @@ Define a Pydantic Model that will be used in the token endpoint for the response
 
 Create a utility function to generate a new access token.
 
-```Python hl_lines="6  12 13 14  28 29 30  78 79 80 81 82 83 84 85 86"
+```Python hl_lines="6  12-14  28-30  78-86"
 {!../../../docs_src/security/tutorial004.py!}
 ```
 
@@ -156,7 +156,7 @@ Decode the received token, verify it, and return the current user.
 
 If the token is invalid, return an HTTP error right away.
 
-```Python hl_lines="89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106"
+```Python hl_lines="89-106"
 {!../../../docs_src/security/tutorial004.py!}
 ```
 
@@ -166,7 +166,7 @@ Create a `timedelta` with the expiration time of the token.
 
 Create a real JWT access token and return it.
 
-```Python hl_lines="115 116 117 118 119 120 121 122 123 124 125 126 127 128"
+```Python hl_lines="115-128"
 {!../../../docs_src/security/tutorial004.py!}
 ```
 
index e6882c7e2c23b2e9940e7a2ed1612f1887cfc241..2aa747847ad54cdcc7c0f597cc6bf69e3932cd22 100644 (file)
@@ -90,7 +90,7 @@ If there is no such user, we return an error saying "incorrect username or passw
 
 For the error, we use the exception `HTTPException`:
 
-```Python hl_lines="3  77 78 79"
+```Python hl_lines="3  77-79"
 {!../../../docs_src/security/tutorial003.py!}
 ```
 
@@ -118,7 +118,7 @@ If your database is stolen, the thief won't have your users' plaintext passwords
 
 So, the thief won't be able to try to use those same passwords in another system (as many users use the same password everywhere, this would be dangerous).
 
-```Python hl_lines="80 81 82 83"
+```Python hl_lines="80-83"
 {!../../../docs_src/security/tutorial003.py!}
 ```
 
@@ -181,7 +181,7 @@ Both of these dependencies will just return an HTTP error if the user doesn't ex
 
 So, in our endpoint, we will only get a user if the user exists, was correctly authenticated, and is active:
 
-```Python hl_lines="58 59 60 61 62 63 64 65 66 67  69 70 71 72  90"
+```Python hl_lines="58-67  69-72  90"
 {!../../../docs_src/security/tutorial003.py!}
 ```
 
index a3f7fae052d24d509d7fed69035f6b4e7e5f654e..59eb6a4fb23dc2657dfabe4c1298df6893554324 100644 (file)
@@ -86,13 +86,13 @@ Let's refer to the file `sql_app/database.py`.
 
 ### Import the SQLAlchemy parts
 
-```Python hl_lines="1 2 3"
+```Python hl_lines="1-3"
 {!../../../docs_src/sql_databases/sql_app/database.py!}
 ```
 
 ### Create a database URL for SQLAlchemy
 
-```Python hl_lines="5 6"
+```Python hl_lines="5-6"
 {!../../../docs_src/sql_databases/sql_app/database.py!}
 ```
 
@@ -120,7 +120,7 @@ The first step is to create a SQLAlchemy "engine".
 
 We will later use this `engine` in other places.
 
-```Python hl_lines="8 9 10"
+```Python hl_lines="8-10"
 {!../../../docs_src/sql_databases/sql_app/database.py!}
 ```
 
@@ -189,7 +189,7 @@ Create classes that inherit from it.
 
 These classes are the SQLAlchemy models.
 
-```Python hl_lines="4 7 8 18 19"
+```Python hl_lines="4  7-8  18-19"
 {!../../../docs_src/sql_databases/sql_app/models.py!}
 ```
 
@@ -205,7 +205,7 @@ We use `Column` from SQLAlchemy as the default value.
 
 And we pass a SQLAlchemy class "type", as `Integer`, `String`, and `Boolean`, that defines the type in the database, as an argument.
 
-```Python hl_lines="1 10 11 12 13 21 22 23 24"
+```Python hl_lines="1  10-13  21-24"
 {!../../../docs_src/sql_databases/sql_app/models.py!}
 ```
 
@@ -217,7 +217,7 @@ For this, we use `relationship` provided by SQLAlchemy ORM.
 
 This will become, more or less, a "magic" attribute that will contain the values from other tables related to this one.
 
-```Python hl_lines="2 15 26"
+```Python hl_lines="2  15  26"
 {!../../../docs_src/sql_databases/sql_app/models.py!}
 ```
 
@@ -248,7 +248,7 @@ So, the user will also have a `password` when creating it.
 
 But for security, the `password` won't be in other Pydantic *models*, for example, it won't be sent from the API when reading a user.
 
-```Python hl_lines="3 6 7 8 11 12 23 24 27 28"
+```Python hl_lines="3  6-8  11-12  23-24  27-28"
 {!../../../docs_src/sql_databases/sql_app/schemas.py!}
 ```
 
@@ -278,7 +278,7 @@ The same way, when reading a user, we can now declare that `items` will contain
 
 Not only the IDs of those items, but all the data that we defined in the Pydantic *model* for reading items: `Item`.
 
-```Python hl_lines="15 16 17 31 32 33 34"
+```Python hl_lines="15-17  31-34"
 {!../../../docs_src/sql_databases/sql_app/schemas.py!}
 ```
 
@@ -293,7 +293,7 @@ This <a href="https://pydantic-docs.helpmanual.io/#config" class="external-link"
 
 In the `Config` class, set the attribute `orm_mode = True`.
 
-```Python hl_lines="15 19 20 31 36 37"
+```Python hl_lines="15  19-20  31  36-37"
 {!../../../docs_src/sql_databases/sql_app/schemas.py!}
 ```
 
@@ -366,7 +366,7 @@ Create utility functions to:
 * Read multiple users.
 * Read a single item.
 
-```Python hl_lines="1 3 6 7 10 11 14 15 27 28"
+```Python hl_lines="1  3  6-7  10-11  14-15  27-28"
 {!../../../docs_src/sql_databases/sql_app/crud.py!}
 ```
 
@@ -384,7 +384,7 @@ The steps are:
 * `commit` the changes to the database (so that they are saved).
 * `refresh` your instance (so that it contains any new data from the database, like the generated ID).
 
-```Python hl_lines="18 19 20 21 22 23 24 31 32 33 34 35 36"
+```Python hl_lines="18-24  31-36"
 {!../../../docs_src/sql_databases/sql_app/crud.py!}
 ```
 
@@ -462,7 +462,7 @@ For that, we will create a new dependency with `yield`, as explained before in t
 
 Our dependency will create a new SQLAlchemy `SessionLocal` that will be used in a single request, and then close it once the request is finished.
 
-```Python hl_lines="15 16 17 18 19 20"
+```Python hl_lines="15-20"
 {!../../../docs_src/sql_databases/sql_app/main.py!}
 ```
 
@@ -492,7 +492,7 @@ This will then give us better editor support inside the *path operation function
 
 Now, finally, here's the standard **FastAPI** *path operations* code.
 
-```Python hl_lines="23 24 25 26 27 28  31 32 33 34  37 38 39 40 41 42  45 46 47 48 49  52 53 54 55"
+```Python hl_lines="23-28  31-34  37-42  45-49  52-55"
 {!../../../docs_src/sql_databases/sql_app/main.py!}
 ```
 
@@ -640,7 +640,7 @@ A "middleware" is basically a function that is always executed for each request,
 
 The middleware we'll add (just a function) will create a new SQLAlchemy `SessionLocal` for each request, add it to the request and then close it once the request is finished.
 
-```Python hl_lines="14 15 16 17 18 19 20 21 22"
+```Python hl_lines="14-22"
 {!../../../docs_src/sql_databases/sql_app/alt_main.py!}
 ```
 
index dd239e6f0da5795e24b32406696b1b8fa4f85510..c103bd940b2f0cd146d86815b9b8e0578726b0a7 100644 (file)
@@ -21,7 +21,7 @@ $ pip install aiofiles
 * Import `StaticFiles`.
 * "Mount" a `StaticFiles()` instance in a specific path.
 
-```Python hl_lines="2 6"
+```Python hl_lines="2  6"
 {!../../../docs_src/static_files/tutorial001.py!}
 ```
 
index e517ae78174cc984e163202416b86111465dfed6..70195b25b993be3e104fbf686139eeeb6054c8ae 100644 (file)
@@ -18,7 +18,7 @@ Use the `TestClient` object the same way as you do with `requests`.
 
 Write simple `assert` statements with the standard Python expressions that you need to check (again, standard `pytest`).
 
-```Python hl_lines="2  12  15 16 17 18"
+```Python hl_lines="2  12  15-18"
 {!../../../docs_src/app_testing/tutorial001.py!}
 ```
 
index 99e2f8b2645e773834712f77634d291903a78e6f..c1d714b287b9b4be09f9d42e8c33427619a4ad4f 100644 (file)
@@ -305,7 +305,7 @@ hamburguesas = get_burgers (2)
 
 Por lo tanto, si estás utilizando una library que te dice que puedes llamarla con `await`, debes crear las *path operation functions* que la usan con `async def`, como en:
 
-```Python hl_lines="2 3"
+```Python hl_lines="2-3"
 @app.get('/burgers')
 async def read_burgers():
     burgers = await get_burgers(2)
index c60c57d6d101ffd30b2b200ffa500e7323e26e26..30e5b1d92aba285a67ac4959d68b92df80c085f1 100644 (file)
@@ -151,7 +151,7 @@ def read_item(item_id: int, q: Optional[str] = None):
 
 Si tu código usa `async` / `await`, usa `async def`:
 
-```Python hl_lines="7 12"
+```Python hl_lines="7  12"
 from fastapi import FastAPI
 from typing import Optional
 
@@ -242,7 +242,7 @@ Ahora modifica el archivo `main.py` para recibir un <abbr title="cuerpo del mens
 
 Declara el body usando las declaraciones de tipo estándares de Python gracias a Pydantic.
 
-```Python hl_lines="2  7 8 9 10  23 24 25"
+```Python hl_lines="2  7-10  23-25"
 from fastapi import FastAPI
 from pydantic import BaseModel
 from typing import Optional
index 84a92af959a64fb22d83f29c37c51c086a65acd1..e9fd61629372eead4e3a3de71674a72dbb99c4cd 100644 (file)
@@ -188,7 +188,7 @@ El editor aún sabe que es un `str` y provee soporte para ello.
 
 Harías lo mismo para declarar `tuple`s y `set`s:
 
-```Python hl_lines="1 4"
+```Python hl_lines="1  4"
 {!../../../docs_src/python_types/tutorial007.py!}
 ```
 
@@ -205,7 +205,7 @@ El primer sub-tipo es para los keys del `dict`.
 
 El segundo sub-tipo es para los valores del `dict`:
 
-```Python hl_lines="1 4"
+```Python hl_lines="1  4"
 {!../../../docs_src/python_types/tutorial008.py!}
 ```
 
@@ -221,7 +221,7 @@ También puedes declarar una clase como el tipo de una variable.
 
 Digamos que tienes una clase `Person`con un nombre:
 
-```Python hl_lines="1 2 3"
+```Python hl_lines="1-3"
 {!../../../docs_src/python_types/tutorial009.py!}
 ```
 
index 88d0c0e3d217d75cce7162d9d1d71fca34d9a00a..687cc7c2bfdb9510796e2e5f35054557f90563cf 100644 (file)
@@ -156,7 +156,7 @@ def read_item(item_id: int, q: str = Optional[None]):
 
 If your code uses `async` / `await`, use `async def`:
 
-```Python hl_lines="7 12"
+```Python hl_lines="7  12"
 from fastapi import FastAPI
 from typing import Optional
 
@@ -247,7 +247,7 @@ Now modify the file `main.py` to receive a body from a `PUT` request.
 
 Declare the body using standard Python types, thanks to Pydantic.
 
-```Python hl_lines="2  7 8 9 10  23 24 25"
+```Python hl_lines="2  7-10  23-25"
 from fastapi import FastAPI
 from pydantic import BaseModel
 from typing import Optional
index dcf7f56b542f1afc4ac7efb38d62a5c3a18fc20d..ed87d6897ab121b42b64d7432df21d3a2d9dc147 100644 (file)
@@ -146,7 +146,7 @@ def read_item(item_id: int, q: Optional[str] = None):
 
 Se seu código utiliza `async` / `await`, use `async def`:
 
-```Python hl_lines="9 14"
+```Python hl_lines="9  14"
 from typing import Optional
 
 from fastapi import FastAPI
@@ -238,7 +238,7 @@ Agora modifique o arquivo `main.py` para receber um corpo para uma requisição
 
 Declare o corpo utilizando tipos padrão Python, graças ao Pydantic.
 
-```Python hl_lines="4  9 10 11 12  25 26 27"
+```Python hl_lines="4  9-12  25-27"
 from fastapi import FastAPI
 from pydantic import BaseModel
 
index 5d5e806e58e84a73b6c6ab6959cfb620f503e9e4..03abddc1d1785e842ed0ea7c4699c5d90744bb3a 100644 (file)
@@ -157,7 +157,7 @@ def read_item(item_id: int, q: Optional[str] = None):
 
 If your code uses `async` / `await`, use `async def`:
 
-```Python hl_lines="9 14"
+```Python hl_lines="9  14"
 from typing import Optional
 
 from fastapi import FastAPI
@@ -249,7 +249,7 @@ Now modify the file `main.py` to receive a body from a `PUT` request.
 
 Declare the body using standard Python types, thanks to Pydantic.
 
-```Python hl_lines="4  9 10 11 12  25 26 27"
+```Python hl_lines="4  9-12  25-27"
 from typing import Optional
 
 from fastapi import FastAPI
index 8db98885d37ef9d0a287f3fad451dd3573187ffe..d236da22c17ff6ef77b4e2844950dd71bed1bed8 100644 (file)
@@ -157,7 +157,7 @@ def read_item(item_id: int, q: Optional[str] = None):
 
 If your code uses `async` / `await`, use `async def`:
 
-```Python hl_lines="9 14"
+```Python hl_lines="9  14"
 from typing import Optional
 
 from fastapi import FastAPI
@@ -249,7 +249,7 @@ Now modify the file `main.py` to receive a body from a `PUT` request.
 
 Declare the body using standard Python types, thanks to Pydantic.
 
-```Python hl_lines="4  9 10 11 12  25 26 27"
+```Python hl_lines="4  9-12  25-27"
 from typing import Optional
 
 from fastapi import FastAPI
index 851255334e122fcedf8ae93cfc580ab86293d048..93d9d98c49e864628ed1abe021944d0056e99af5 100644 (file)
@@ -153,7 +153,7 @@ def read_item(item_id: int, q: Optional[str] = None):
 
 如果你的代码里会出现 `async` / `await`,请使用 `async def`:
 
-```Python hl_lines="9 14"
+```Python hl_lines="9  14"
 from typing import Optional
 
 from fastapi import FastAPI
@@ -245,7 +245,7 @@ INFO:     Application startup complete.
 
 我们借助 Pydantic 来使用标准的 Python 类型声明请求体。
 
-```Python hl_lines="4  9 10 11 12  25 26 27"
+```Python hl_lines="4  9-12  25-27"
 from typing import Optional
 
 from fastapi import FastAPI
index 0c9e9db470ed17db165312d4465d19bacad5f462..e8c07f4c38c30bd28a160e7c77c015ec17448a2e 100644 (file)
@@ -188,7 +188,7 @@ John Doe
 
 声明 `tuple` 和 `set` 的方法也是一样的:
 
-```Python hl_lines="1 4"
+```Python hl_lines="1  4"
 {!../../../docs_src/python_types/tutorial007.py!}
 ```
 
@@ -205,7 +205,7 @@ John Doe
 
 第二个子类型声明 `dict` 的所有值:
 
-```Python hl_lines="1 4"
+```Python hl_lines="1  4"
 {!../../../docs_src/python_types/tutorial008.py!}
 ```
 
@@ -221,7 +221,7 @@ John Doe
 
 假设你有一个名为 `Person` 的类,拥有 name 属性:
 
-```Python hl_lines="1 2 3"
+```Python hl_lines="1-3"
 {!../../../docs_src/python_types/tutorial009.py!}
 ```
 
index 2df08d8b62b3b52559716f4b5ecb499612b615b8..053cae71c7c6f121c142cbf8c75468fbab95fc62 100644 (file)
@@ -17,7 +17,7 @@
 
 然后,你可以对模型属性使用 `Field`:
 
-```Python hl_lines="9 10"
+```Python hl_lines="9-10"
 {!../../../docs_src/body_fields/tutorial001.py!}
 ```
 
index 73cb0c90c90f59a0b21026fd7679de241dea21e2..0176902d05dbfd2108c3a68e9456747167611d5b 100644 (file)
@@ -8,7 +8,7 @@
 
 你还可以通过将默认值设置为 `None` 来将请求体参数声明为可选参数:
 
-```Python hl_lines="17 18 19"
+```Python hl_lines="17-19"
 {!../../../docs_src/body_multiple_params/tutorial001.py!}
 ```
 
index e60dce963d7c598be408980a81c1c5b8823170b9..4d15b7fcf28fe8235b116984f260ed2098650f32 100644 (file)
@@ -27,7 +27,7 @@
 
 使用标准的 Python 类型来声明所有属性:
 
-```Python hl_lines="5 6 7 8 9"
+```Python hl_lines="5-9"
 {!../../../docs_src/body/tutorial001.py!}
 ```
 
@@ -122,7 +122,7 @@ Pydantic 本身甚至也进行了一些更改以支持此功能。
 
 **FastAPI** 将识别出与路径参数匹配的函数参数应**从路径中获取**,而声明为 Pydantic 模型的函数参数应**从请求体中获取**。
 
-```Python hl_lines="15 16"
+```Python hl_lines="15-16"
 {!../../../docs_src/body/tutorial003.py!}
 ```
 
index db35e95643cb9c0609b6be60983e4954bbdca63e..1b428d66271124c7e4aa12b9884e2fad66c8cbcf 100644 (file)
@@ -2,7 +2,7 @@
 
 你可以使用与 Python 格式化字符串相同的语法来声明路径"参数"或"变量":
 
-```Python hl_lines="6 7"
+```Python hl_lines="6-7"
 {!../../../docs_src/path_params/tutorial001.py!}
 ```
 
 然后,你还可以使用路径 `/users/{user_id}` 来通过用户 ID 获取关于特定用户的数据。
 
 由于*路径操作*是按顺序依次运行的,你需要确保路径 `/users/me` 声明在路径 `/users/{user_id}`之前:
-```Python hl_lines="6 11"
+```Python hl_lines="6  11"
 {!../../../docs_src/path_params/tutorial003.py!}
 ```
 
 
 然后创建具有固定值的类属性,这些固定值将是可用的有效值:
 
-```Python hl_lines="1 6 7 8 9"
+```Python hl_lines="1  6-9"
 {!../../../docs_src/path_params/tutorial005.py!}
 ```
 
 
 在返回给客户端之前,它们将被转换为对应的值:
 
-```Python hl_lines="18 20 21"
+```Python hl_lines="18-21"
 {!../../../docs_src/path_params/tutorial005.py!}
 ```
 
index c91392cde62edc5dff037b5abee187fc0b616226..36f17beb96ae2e5d12b03d21b18f0f96491d8d3e 100644 (file)
@@ -121,7 +121,7 @@ http://127.0.0.1:8000/items/foo?short=yes
 
 它们将通过名称被检测到:
 
-```Python hl_lines="6 8"
+```Python hl_lines="6  8"
 {!../../../docs_src/query_params/tutorial004.py!}
 ```
 
@@ -133,7 +133,7 @@ http://127.0.0.1:8000/items/foo?short=yes
 
 但当你想让一个查询参数成为必需的,不声明任何默认值就可以:
 
-```Python hl_lines="6 7"
+```Python hl_lines="6-7"
 {!../../../docs_src/query_params/tutorial005.py!}
 ```