Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 36 additions & 9 deletions docs/zh/docs/tutorial/query-params.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,19 @@ http://127.0.0.1:8000/items/?skip=20

参数还可以声明为 `bool` 类型,FastAPI 会自动转换参数类型:

```Python hl_lines="9"
{!../../../docs_src/query_params/tutorial003.py!}
```

=== "Python 3.10+"

```Python hl_lines="7"
{!> ../../../docs_src/query_params/tutorial003_py310.py!}
```

=== "Python 3.8+"

```Python hl_lines="9"
{!> ../../../docs_src/query_params/tutorial003.py!}
```


本例中,访问:

Expand Down Expand Up @@ -137,9 +147,18 @@ http://127.0.0.1:8000/items/foo?short=yes

FastAPI 通过参数名进行检测:

```Python hl_lines="8 10"
{!../../../docs_src/query_params/tutorial004.py!}
```
=== "Python 3.10+"

```Python hl_lines="6 8"
{!> ../../../docs_src/query_params/tutorial004_py310.py!}
```

=== "Python 3.8+"

```Python hl_lines="8 10"
{!> ../../../docs_src/query_params/tutorial004.py!}
```


## 必选查询参数

Expand Down Expand Up @@ -195,9 +214,17 @@ http://127.0.0.1:8000/items/foo-item?needy=sooooneedy

当然,把一些参数定义为必选,为另一些参数设置默认值,再把其它参数定义为可选,这些操作都是可以的:

```Python hl_lines="10"
{!../../../docs_src/query_params/tutorial006.py!}
```
=== "Python 3.10+"

```Python hl_lines="8"
{!> ../../../docs_src/query_params/tutorial006_py310.py!}
```

=== "Python 3.8+"

```Python hl_lines="10"
{!> ../../../docs_src/query_params/tutorial006.py!}
```

本例中有 3 个查询参数:

Expand Down