-
-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
๐ Add Korean translation for Tutorial - Query Parameters (#2390)
Co-authored-by: Sebastiรกn Ramรญrez <tiangolo@gmail.com>
- Loading branch information
1 parent
61db5eb
commit 388e5c0
Showing
2 changed files
with
199 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
# ์ฟผ๋ฆฌ ๋งค๊ฐ๋ณ์ | ||
|
||
๊ฒฝ๋ก ๋งค๊ฐ๋ณ์์ ์ผ๋ถ๊ฐ ์๋ ๋ค๋ฅธ ํจ์ ๋งค๊ฐ๋ณ์๋ฅผ ์ ์ธํ ๋, "์ฟผ๋ฆฌ" ๋งค๊ฐ๋ณ์๋ก ์๋ ํด์ํฉ๋๋ค. | ||
|
||
```Python hl_lines="9" | ||
{!../../../docs_src/query_params/tutorial001.py!} | ||
``` | ||
|
||
์ฟผ๋ฆฌ๋ URL์์ `?` ํ์ ๋์ค๊ณ `&`์ผ๋ก ๊ตฌ๋ถ๋๋ ํค-๊ฐ ์์ ์งํฉ์ ๋๋ค. | ||
|
||
์๋ฅผ ๋ค์ด, URL์์: | ||
|
||
``` | ||
http://127.0.0.1:8000/items/?skip=0&limit=10 | ||
``` | ||
|
||
...์ฟผ๋ฆฌ ๋งค๊ฐ๋ณ์๋: | ||
|
||
* `skip`: ๊ฐ `0`์ ๊ฐ์ง๋๋ค. | ||
* `limit`: ๊ฐ `10`์ ๊ฐ์ง๋๋ค. | ||
|
||
URL์ ์ผ๋ถ์ด๋ฏ๋ก "์์ฐ์ค๋ฝ๊ฒ" ๋ฌธ์์ด์ ๋๋ค. | ||
|
||
ํ์ง๋ง ํ์ด์ฌ ํ์ ๊ณผ ํจ๊ป ์ ์ธํ ๊ฒฝ์ฐ(์ ์์์ `int`), ํด๋น ํ์ ์ผ๋ก ๋ณํ๋๊ณ ์ด์ ๋ํด ๊ฒ์ฆํฉ๋๋ค. | ||
|
||
๊ฒฝ๋ก ๋งค๊ฐ๋ณ์์ ์ ์ฉ๋ ๋์ผํ ํ๋ก์ธ์ค๊ฐ ์ฟผ๋ฆฌ ๋งค๊ฐ๋ณ์์๋ ์ ์ฉ๋ฉ๋๋ค: | ||
|
||
* (๋น์ฐํ) ํธ์ง๊ธฐ ์ง์ | ||
* ๋ฐ์ดํฐ <abbr title="HTTP ์์ฒญ์์ ์ ๋ฌ๋๋ ๋ฌธ์์ด์ ํ์ด์ฌ ๋ฐ์ดํฐ๋ก ๋ณํ">"ํ์ฑ"</abbr> | ||
* ๋ฐ์ดํฐ ๊ฒ์ฆ | ||
* ์๋ ๋ฌธ์ํ | ||
|
||
## ๊ธฐ๋ณธ๊ฐ | ||
|
||
์ฟผ๋ฆฌ ๋งค๊ฐ๋ณ์๋ ๊ฒฝ๋ก์์ ๊ณ ์ ๋ ๋ถ๋ถ์ด ์๋๊ธฐ ๋๋ฌธ์ ์ ํ์ ์ผ ์ ์๊ณ ๊ธฐ๋ณธ๊ฐ์ ๊ฐ์ง ์ ์์ต๋๋ค. | ||
|
||
์ ์์์ `skip=0`๊ณผ `limit=10`์ ๊ธฐ๋ณธ๊ฐ์ ๊ฐ๊ณ ์์ต๋๋ค. | ||
|
||
๊ทธ๋ฌ๋ฏ๋ก URL๋ก ์ด๋ํ๋ฉด: | ||
|
||
``` | ||
http://127.0.0.1:8000/items/ | ||
``` | ||
|
||
์๋๋ก ์ด๋ํ ๊ฒ๊ณผ ๊ฐ์ต๋๋ค: | ||
|
||
``` | ||
http://127.0.0.1:8000/items/?skip=0&limit=10 | ||
``` | ||
|
||
ํ์ง๋ง ๊ฐ๋ น ์๋๋ก ์ด๋ํ ๊ฒฝ์ฐ: | ||
|
||
``` | ||
http://127.0.0.1:8000/items/?skip=20 | ||
``` | ||
|
||
ํจ์์ ๋งค๊ฐ๋ณ์ ๊ฐ์ ์๋๊ฐ ๋ฉ๋๋ค: | ||
|
||
* `skip=20`: URL์์ ์ง์ ํ๊ธฐ ๋๋ฌธ์ ๋๋ค | ||
* `limit=10`: ๊ธฐ๋ณธ๊ฐ์ด๊ธฐ ๋๋ฌธ์ ๋๋ค | ||
|
||
## ์ ํ์ ๋งค๊ฐ๋ณ์ | ||
|
||
๊ฐ์ ๋ฐฉ๋ฒ์ผ๋ก ๊ธฐ๋ณธ๊ฐ์ `None`์ผ๋ก ์ค์ ํ์ฌ ์ ํ์ ๋งค๊ฐ๋ณ์๋ฅผ ์ ์ธํ ์ ์์ต๋๋ค: | ||
|
||
```Python hl_lines="9" | ||
{!../../../docs_src/query_params/tutorial002.py!} | ||
``` | ||
|
||
์ด ๊ฒฝ์ฐ ํจ์ ๋งค๊ฐ๋ณ์ `q`๋ ์ ํ์ ์ด๋ฉฐ ๊ธฐ๋ณธ๊ฐ์ผ๋ก `None` ๊ฐ์ด ๋ฉ๋๋ค. | ||
|
||
!!! check "ํ์ธ" | ||
**FastAPI**๋ `item_id`๊ฐ ๊ฒฝ๋ก ๋งค๊ฐ๋ณ์์ด๊ณ `q`๋ ๊ฒฝ๋ก ๋งค๊ฐ๋ณ์๊ฐ ์๋ ์ฟผ๋ฆฌ ๋งค๊ฐ๋ณ์๋ผ๋ ๊ฒ์ ์ ์ ๋๋ก ์ถฉ๋ถํ ๋๋ํฉ๋๋ค. | ||
|
||
!!! note "์ฐธ๊ณ " | ||
FastAPI๋ `q`๊ฐ `= None`์ด๋ฏ๋ก ์ ํ์ ์ด๋ผ๋ ๊ฒ์ ์ธ์งํฉ๋๋ค. | ||
|
||
`Optional[str]`์ ์๋ `Optional`์ FastAPI(FastAPI๋ `str` ๋ถ๋ถ๋ง ์ฌ์ฉํฉ๋๋ค)๊ฐ ์ฌ์ฉํ๋๊ฒ ์๋์ง๋ง, `Optional[str]`์ ํธ์ง๊ธฐ์๊ฒ ์ฝ๋์์ ์ค๋ฅ๋ฅผ ์ฐพ์๋ผ ์ ์๊ฒ ๋์์ค๋๋ค. | ||
|
||
## ์ฟผ๋ฆฌ ๋งค๊ฐ๋ณ์ ํ๋ณํ | ||
|
||
`bool` ํ์ผ๋ก ์ ์ธํ ์๋ ์๊ณ , ์๋์ฒ๋ผ ๋ณํ๋ฉ๋๋ค: | ||
|
||
```Python hl_lines="9" | ||
{!../../../docs_src/query_params/tutorial003.py!} | ||
``` | ||
|
||
์ด ๊ฒฝ์ฐ, ์๋๋ก ์ด๋ํ๋ฉด: | ||
|
||
``` | ||
http://127.0.0.1:8000/items/foo?short=1 | ||
``` | ||
|
||
๋๋ | ||
|
||
``` | ||
http://127.0.0.1:8000/items/foo?short=True | ||
``` | ||
|
||
๋๋ | ||
|
||
``` | ||
http://127.0.0.1:8000/items/foo?short=true | ||
``` | ||
|
||
๋๋ | ||
|
||
``` | ||
http://127.0.0.1:8000/items/foo?short=on | ||
``` | ||
|
||
๋๋ | ||
|
||
``` | ||
http://127.0.0.1:8000/items/foo?short=yes | ||
``` | ||
|
||
๋๋ ๋ค๋ฅธ ์ด๋ค ๋ณํ(๋๋ฌธ์, ์ฒซ๊ธ์๋ง ๋๋ฌธ์ ๋ฑ)์ด๋๋ผ๋ ํจ์๋ ๋งค๊ฐ๋ณ์ `bool`ํ์ ๊ฐ์ง `short`์ ๊ฐ์ด `True`์์ ์๋๋ค. ๊ทธ๋ ์ง ์์ ๊ฒฝ์ฐ `False`์ ๋๋ค. | ||
|
||
|
||
## ์ฌ๋ฌ ๊ฒฝ๋ก/์ฟผ๋ฆฌ ๋งค๊ฐ๋ณ์ | ||
|
||
์ฌ๋ฌ ๊ฒฝ๋ก ๋งค๊ฐ๋ณ์์ ์ฟผ๋ฆฌ ๋งค๊ฐ๋ณ์๋ฅผ ๋์์ ์ ์ธํ ์ ์์ผ๋ฉฐ **FastAPI**๋ ์ด๋ ๊ฒ์ด ๋ฌด์์ธ์ง ์๊ณ ์์ต๋๋ค. | ||
|
||
๊ทธ๋ฆฌ๊ณ ํน์ ์์๋ก ์ ์ธํ ํ์๊ฐ ์์ต๋๋ค. | ||
|
||
๋งค๊ฐ๋ณ์๋ค์ ์ด๋ฆ์ผ๋ก ๊ฐ์ง๋ฉ๋๋ค: | ||
|
||
```Python hl_lines="8 10" | ||
{!../../../docs_src/query_params/tutorial004.py!} | ||
``` | ||
|
||
## ํ์ ์ฟผ๋ฆฌ ๋งค๊ฐ๋ณ์ | ||
|
||
๊ฒฝ๋ก๊ฐ ์๋ ๋งค๊ฐ๋ณ์์ ๋ํ ๊ธฐ๋ณธ๊ฐ์ ์ ์ธํ ๋(์ง๊ธ์ ์ฟผ๋ฆฌ ๋งค๊ฐ๋ณ์๋ง ๋ณด์์ต๋๋ค), ํด๋น ๋งค๊ฐ๋ณ์๋ ํ์์ (Required)์ด์ง ์์์ต๋๋ค. | ||
|
||
ํน์ ๊ฐ์ ์ถ๊ฐํ์ง ์๊ณ ์ ํ์ ์ผ๋ก ๋ง๋ค๊ธฐ ์ํด์ ๊ธฐ๋ณธ๊ฐ์ `None`์ผ๋ก ์ค์ ํ๋ฉด ๋ฉ๋๋ค. | ||
|
||
๊ทธ๋ฌ๋ ์ฟผ๋ฆฌ ๋งค๊ฐ๋ณ์๋ฅผ ํ์๋ก ๋ง๋ค๋ ค๋ฉด ๊ธฐ๋ณธ๊ฐ์ ์ ์ธํ ์ ์์ต๋๋ค: | ||
|
||
```Python hl_lines="6-7" | ||
{!../../../docs_src/query_params/tutorial005.py!} | ||
``` | ||
|
||
์ฌ๊ธฐ ์ฟผ๋ฆฌ ๋งค๊ฐ๋ณ์ `needy`๋ `str`ํ์ธ ํ์ ์ฟผ๋ฆฌ ๋งค๊ฐ๋ณ์์ ๋๋ค. | ||
|
||
๋ธ๋ผ์ฐ์ ์์ URL์ ์๋์ฒ๋ผ ์ฐ๋ค๋ฉด: | ||
|
||
``` | ||
http://127.0.0.1:8000/items/foo-item | ||
``` | ||
|
||
...ํ์ ๋งค๊ฐ๋ณ์ `needy`๋ฅผ ๋ฃ์ง ์์๊ธฐ ๋๋ฌธ์ ์๋์ ๊ฐ์ ์ค๋ฅ๋ฅผ ๋ณด๊ฒ ๋ฉ๋๋ค: | ||
|
||
```JSON | ||
{ | ||
"detail": [ | ||
{ | ||
"loc": [ | ||
"query", | ||
"needy" | ||
], | ||
"msg": "field required", | ||
"type": "value_error.missing" | ||
} | ||
] | ||
} | ||
``` | ||
|
||
`needy`๋ ํ์ ๋งค๊ฐ๋ณ์์ด๋ฏ๋ก URL์ ๋ฐ๋์ ์ค์ ํด์ค์ผ ํฉ๋๋ค: | ||
|
||
``` | ||
http://127.0.0.1:8000/items/foo-item?needy=sooooneedy | ||
``` | ||
|
||
...์๋์ฒ๋ผ ์๋ํฉ๋๋ค: | ||
|
||
```JSON | ||
{ | ||
"item_id": "foo-item", | ||
"needy": "sooooneedy" | ||
} | ||
``` | ||
|
||
๊ทธ๋ฆฌ๊ณ ๋ฌผ๋ก , ์ผ๋ถ ๋งค๊ฐ๋ณ์๋ ํ์๋ก, ๋ค๋ฅธ ์ผ๋ถ๋ ๊ธฐ๋ณธ๊ฐ์, ๋ ๋ค๋ฅธ ์ผ๋ถ๋ ์ ํ์ ์ผ๋ก ์ ์ธํ ์ ์์ต๋๋ค: | ||
|
||
```Python hl_lines="10" | ||
{!../../../docs_src/query_params/tutorial006.py!} | ||
``` | ||
|
||
์ด ๊ฒฝ์ฐ 3๊ฐ์ง ์ฟผ๋ฆฌ ๋งค๊ฐ๋ณ์๊ฐ ์์ต๋๋ค: | ||
|
||
* `needy`, ํ์์ ์ธ `str`. | ||
* `skip`, ๊ธฐ๋ณธ๊ฐ์ด `0`์ธ `int`. | ||
* `limit`, ์ ํ์ ์ธ `int`. | ||
|
||
!!! tip "ํ" | ||
[๊ฒฝ๋ก ๋งค๊ฐ๋ณ์](path-params.md#predefined-values){.internal-link target=_blank}์ ๋ง์ฐฌ๊ฐ์ง๋ก `Enum`์ ์ฌ์ฉํ ์ ์์ต๋๋ค. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters