You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
Es gibt eine Alternative, die explizit deklariert, dass ein Wert erforderlich ist. Sie können als Default das <abbrtitle='Zeichenfolge, die einen Wert direkt darstellt, etwa 1, "hallowelt", True, None'>Literal</abbr>`...` setzen:
Falls Sie das`...` bisher noch nicht gesehen haben: Es ist ein spezieller einzelner Wert, <ahref="https://docs.python.org/3/library/constants.html#Ellipsis"class="external-link"target="_blank">Teil von Python und wird „Ellipsis“ genannt</a> (Deutsch: Ellipse).
327
-
328
-
Es wird von Pydantic und FastAPI verwendet, um explizit zu deklarieren, dass ein Wert erforderlich ist.
329
-
330
-
///
331
-
332
-
Dies wird**FastAPI** wissen lassen, dass dieser Parameter erforderlich ist.
333
-
334
318
###Erforderlich, kann`None` sein
335
319
336
320
Sie können deklarieren, dass ein Parameter`None` akzeptiert, aber dennoch erforderlich ist. Das zwingt Clients, den Wert zu senden, selbst wenn er`None` ist.
Copy file name to clipboardExpand all lines: docs/en/docs/release-notes.md
+19Lines changed: 19 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,12 +7,28 @@ hide:
7
7
8
8
## Latest Changes
9
9
10
+
### Refactors
11
+
12
+
* ✅ Simplify tests for `query_params_str_validations`. PR [#13218](https://github.com/fastapi/fastapi/pull/13218) by [@alv2017](https://github.com/alv2017).
13
+
* ✅ Simplify tests for `app_testing`. PR [#13220](https://github.com/fastapi/fastapi/pull/13220) by [@alv2017](https://github.com/alv2017).
14
+
* ✅ Simplify tests for `dependency_testing`. PR [#13223](https://github.com/fastapi/fastapi/pull/13223) by [@alv2017](https://github.com/alv2017).
15
+
10
16
### Docs
11
17
18
+
* 🐛 Fix issue with Swagger theme change example in the official tutorial. PR [#13289](https://github.com/fastapi/fastapi/pull/13289) by [@Zerohertz](https://github.com/Zerohertz).
19
+
* 📝 Add more precise description of HTTP status code range in docs. PR [#13347](https://github.com/fastapi/fastapi/pull/13347) by [@DanielYang59](https://github.com/DanielYang59).
20
+
* 🔥 Remove manual type annotations in JWT tutorial to avoid typing expectations (JWT doesn't provide more types). PR [#13378](https://github.com/fastapi/fastapi/pull/13378) by [@tiangolo](https://github.com/tiangolo).
21
+
* 📝 Update docs for Query Params and String Validations, remove obsolete Ellipsis docs (`...`). PR [#13377](https://github.com/fastapi/fastapi/pull/13377) by [@tiangolo](https://github.com/tiangolo).
22
+
* ✏️ Remove duplicate title in docs `body-multiple-params`. PR [#13345](https://github.com/fastapi/fastapi/pull/13345) by [@DanielYang59](https://github.com/DanielYang59).
12
23
* 📝 Fix test badge. PR [#13313](https://github.com/fastapi/fastapi/pull/13313) by [@esadek](https://github.com/esadek).
13
24
14
25
### Translations
15
26
27
+
* 🌐 Update Korean translation for `docs/ko/docs/help-fastapi.md`. PR [#13262](https://github.com/fastapi/fastapi/pull/13262) by [@Zerohertz](https://github.com/Zerohertz).
28
+
* 🌐 Add Korean translation for `docs/ko/docs/advanced/custom-response.md`. PR [#13265](https://github.com/fastapi/fastapi/pull/13265) by [@11kkw](https://github.com/11kkw).
29
+
* 🌐 Update Korean translation for `docs/ko/docs/tutorial/security/simple-oauth2.md`. PR [#13335](https://github.com/fastapi/fastapi/pull/13335) by [@yes0ng](https://github.com/yes0ng).
30
+
* 🌐 Add Russian translation for `docs/ru/docs/advanced/response-cookies.md`. PR [#13327](https://github.com/fastapi/fastapi/pull/13327) by [@Stepakinoyan](https://github.com/Stepakinoyan).
31
+
* 🌐 Add Vietnamese translation for `docs/vi/docs/tutorial/static-files.md`. PR [#11291](https://github.com/fastapi/fastapi/pull/11291) by [@ptt3199](https://github.com/ptt3199).
16
32
* 🌐 Add Korean translation for `docs/ko/docs/tutorial/dependencies/dependencies-with-yield.md`. PR [#13257](https://github.com/fastapi/fastapi/pull/13257) by [@11kkw](https://github.com/11kkw).
17
33
* 🌐 Add Vietnamese translation for `docs/vi/docs/virtual-environments.md`. PR [#13282](https://github.com/fastapi/fastapi/pull/13282) by [@ptt3199](https://github.com/ptt3199).
18
34
* 🌐 Add Ukrainian translation for `docs/uk/docs/tutorial/static-files.md`. PR [#13285](https://github.com/fastapi/fastapi/pull/13285) by [@valentinDruzhinin](https://github.com/valentinDruzhinin).
@@ -26,6 +42,9 @@ hide:
26
42
27
43
### Internal
28
44
45
+
* 🔧 Update team: Add Ludovico. PR [#13390](https://github.com/fastapi/fastapi/pull/13390) by [@tiangolo](https://github.com/tiangolo).
46
+
* 🔧 Update sponsors: Add LambdaTest. PR [#13389](https://github.com/fastapi/fastapi/pull/13389) by [@tiangolo](https://github.com/tiangolo).
47
+
* ⬆ Bump cloudflare/wrangler-action from 3.13 to 3.14. PR [#13350](https://github.com/fastapi/fastapi/pull/13350) by [@dependabot[bot]](https://github.com/apps/dependabot).
29
48
* ⬆ Bump mkdocs-material from 9.5.18 to 9.6.1. PR [#13301](https://github.com/fastapi/fastapi/pull/13301) by [@dependabot[bot]](https://github.com/apps/dependabot).
30
49
* ⬆ Bump pillow from 11.0.0 to 11.1.0. PR [#13300](https://github.com/fastapi/fastapi/pull/13300) by [@dependabot[bot]](https://github.com/apps/dependabot).
31
50
* 👥 Update FastAPI People - Sponsors. PR [#13295](https://github.com/fastapi/fastapi/pull/13295) by [@tiangolo](https://github.com/tiangolo).
The query parameter`q` is of type`Union[str, None]` (or`str| None` in Python 3.10), that means that it's of type`str` but could also be`None`, and indeed, the default value is`None`, so FastAPI will know it's not required.
9
+
The query parameter`q` is of type`str| None`, that means that it's of type`str` but could also be`None`, and indeed, the default value is`None`, so FastAPI will know it's not required.
10
10
11
11
/// note
12
12
13
13
FastAPI will know that the value of`q` is not required because of the default value`= None`.
14
14
15
-
The`Union` in`Union[str,None]` will allow your editor to give you better support and detect errors.
15
+
Having`str |None` will allow your editor to give you better support and detect errors.
16
16
17
17
///
18
18
@@ -25,29 +25,9 @@ We are going to enforce that even though `q` is optional, whenever it is provide
25
25
To achieve that, first import:
26
26
27
27
*`Query` from`fastapi`
28
-
*`Annotated` from`typing` (or from`typing_extensions` in Python below 3.9)
28
+
*`Annotated` from`typing`
29
29
30
-
//// tab | Python 3.10+
31
-
32
-
In Python 3.9 or above,`Annotated` is part of the standard library, so you can import it from`typing`.
This will validate the data, show a clear error when the data is not valid, and document the parameter in the OpenAPI schema*path operation*.
@@ -201,7 +150,7 @@ This will validate the data, show a clear error when the data is not valid, and
201
150
202
151
Keep in mind that when using`Query` inside of`Annotated` you cannot use the`default` parameter for`Query`.
203
152
204
-
Instead use the actual default value of the function parameter. Otherwise, it would be inconsistent.
153
+
Instead, use the actual default value of the function parameter. Otherwise, it would be inconsistent.
205
154
206
155
For example, this is not allowed:
207
156
@@ -255,7 +204,7 @@ This specific regular expression pattern checks that the received parameter valu
255
204
256
205
If you feel lost with all these**"regular expression"** ideas, don't worry. They are a hard topic for many people. You can still do a lot of stuff without needing regular expressions yet.
257
206
258
-
But wheneveryouneed them and go and learnthem, know thatyou canalreadyuse them directly in**FastAPI**.
207
+
Nowyouknow that whenever you needthemyou can use them in**FastAPI**.
259
208
260
209
###Pydantic v1`regex` instead of`pattern`
261
210
@@ -296,23 +245,15 @@ q: str
296
245
instead of:
297
246
298
247
```Python
299
-
q:Union[str,None]=None
248
+
q:str|None=None
300
249
```
301
250
302
251
But we are now declaring it with`Query`, for example like:
If you hadn't seen that`...` before: it is a special single value, it is <ahref="https://docs.python.org/3/library/constants.html#Ellipsis"class="external-link"target="_blank">part of Python and is called "Ellipsis"</a>.
333
-
334
-
It is used by Pydantic and FastAPI to explicitly declare that a value is required.
335
-
336
-
///
337
-
338
-
This will let**FastAPI** know that this parameter is required.
339
-
340
265
###Required, can be`None`
341
266
342
267
You can declare that a parameter can accept`None`, but that it's still required. This would force clients to send a value, even if the value is`None`.
343
268
344
-
To do that, you can declare that`None` is a valid type butstill use`...` as the default:
269
+
To do that, you can declare that`None` is a valid type butsimply do not declare a default value:
Pydantic, which is what powers all the data validation and serialization in FastAPI, has a special behavior when you use`Optional` or`Union[Something, None]` without a default value, you can read more about it in the Pydantic docs about <ahref="https://docs.pydantic.dev/2.3/usage/models/#required-optional-fields"class="external-link"target="_blank">Required fields</a>.
351
-
352
-
///
353
-
354
-
/// tip
355
-
356
-
Remember that in most of the cases, when something is required, you can simply omit the default, so you normally don't have to use`...`.
357
-
358
-
///
359
-
360
273
##Query parameter list / multiple values
361
274
362
275
When you define a query parameter explicitly with`Query` you can also declare it to receive a list of values, or said in another way, to receive multiple values.
@@ -396,7 +309,7 @@ The interactive API docs will update accordingly, to allow multiple values:
396
309
397
310
###Query parameter list / multiple values with defaults
398
311
399
-
And you can also define a default`list` of values if none are provided:
312
+
You can also define a default`list` of values if none are provided:
Copy file name to clipboardExpand all lines: docs/en/docs/tutorial/response-status-code.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -53,16 +53,16 @@ These status codes have a name associated to recognize them, but the important p
53
53
54
54
In short:
55
55
56
-
*`100` and above are for "Information". You rarely use them directly. Responses with these status codes cannot have a body.
57
-
***`200`** and above are for "Successful" responses. These are the ones you would use the most.
56
+
*`100 - 199` are for "Information". You rarely use them directly. Responses with these status codes cannot have a body.
57
+
***`200 - 299`** are for "Successful" responses. These are the ones you would use the most.
58
58
*`200` is the default status code, which means everything was "OK".
59
59
* Another example would be`201`, "Created". It is commonly used after creating a new record in the database.
60
60
* A special case is`204`, "No Content". This response is used when there is no content to return to the client, and so the response must not have a body.
61
-
***`300`** and above are for "Redirection". Responses with these status codes may or may not have a body, except for`304`, "Not Modified", which must not have one.
62
-
***`400`** and above are for "Client error" responses. These are the second type you would probably use the most.
61
+
***`300 - 399`** are for "Redirection". Responses with these status codes may or may not have a body, except for`304`, "Not Modified", which must not have one.
62
+
***`400 - 499`** are for "Client error" responses. These are the second type you would probably use the most.
63
63
* An example is`404`, for a "Not Found" response.
64
64
* For generic errors from the client, you can just use`400`.
65
-
*`500` and above are for server errors. You almost never use them directly. When something goes wrong at some part in your application code, or server, it will automatically return one of these status codes.
65
+
*`500 - 599` are for server errors. You almost never use them directly. When something goes wrong at some part in your application code, or server, it will automatically return one of these status codes.