mirror of https://github.com/tiangolo/fastapi.git
Update text in docs
This commit is contained in:
parent
1de6fc107e
commit
9f6fe4a894
|
|
@ -246,9 +246,9 @@ So, when you need to declare a value as required while using `Query`, you can si
|
|||
|
||||
### Required, can be `None` { #required-can-be-none }
|
||||
|
||||
You might want to declare that a parameter can accept `None`, but is still required.
|
||||
You might want to declare a parameter that can accept `None` but is still required.
|
||||
|
||||
However, because of how **HTTP query parameters** work, clients cannot actually send a real `None` (or `null`) value — query parameters are always sent as **strings**.
|
||||
However, because of how **HTTP query parameters** work, clients can not actually send a real `None` (or `null`) value - query parameters are always sent as **strings**.
|
||||
That means you cannot truly have a *required* parameter that also allows a real `None` value.
|
||||
|
||||
For example, you might try:
|
||||
|
|
@ -257,19 +257,12 @@ For example, you might try:
|
|||
q: Annotated[str | None, Query(min_length=3)] = ...
|
||||
```
|
||||
|
||||
But this will still expect a **string** value, and if the client omits `q` or tries to send `q=None`, FastAPI will raise a **request validation error**.
|
||||
In other words, `None` is not an acceptable runtime value for query parameters — only strings are.
|
||||
But this will still expect a **string** value, and if the client tries to send `q=None`, `q=null` or `q=`, these values will be treated by FastAPI as strings `"None"`, `"null"` and `""` (empty string) respectively.
|
||||
|
||||
If you want to accept special values (like `"None"` or an empty string) and interpret them as `None` in your application, you can handle them manually in your function:
|
||||
|
||||
{* ../../docs_src/query_params_str_validations/tutorial006c_an_py310.py hl[9:12,17] *}
|
||||
|
||||
/// note
|
||||
|
||||
This example uses `BeforeValidator`, which is only available in **Pydantic v2**.
|
||||
|
||||
///
|
||||
|
||||
## Query parameter list / multiple values { #query-parameter-list-multiple-values }
|
||||
|
||||
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.
|
||||
|
|
|
|||
Loading…
Reference in New Issue