Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.7k
🌐 Add Russian translation fordocs/ru/docs/tutorial/cookie-param-models.md#13616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
alejsdev merged 1 commit intofastapi:masterfromEgorOnishchuk:translate-ru-tutorial-cookie-param-modelsMay 30, 2025
+76 −0
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
76 changes: 76 additions & 0 deletionsdocs/ru/docs/tutorial/cookie-param-models.md
This file contains hidden or 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,76 @@ | ||
| # Модели параметров cookie | ||
| Если у вас есть группа **cookies**, которые связаны между собой, вы можете создать **Pydantic-модель** для их объявления. 🍪 | ||
| Это позволит вам **переиспользовать модель** в **разных местах**, а также объявить проверки и метаданные сразу для всех параметров. 😎 | ||
| /// note | Заметка | ||
| Этот функционал доступен с версии `0.115.0`. 🤓 | ||
| /// | ||
| /// tip | Совет | ||
| Такой же подход применяется для `Query`, `Cookie`, и `Header`. 😎 | ||
| /// | ||
| ## Pydantic-модель для cookies | ||
| Объявите параметры **cookie**, которые вам нужны, в **Pydantic-модели**, а затем объявите параметр как `Cookie`: | ||
| {* ../../docs_src/cookie_param_models/tutorial001_an_py310.py hl[9:12,16] *} | ||
| **FastAPI** **извлечёт** данные для **каждого поля** из **cookies**, полученных в запросе, и выдаст вам объявленную Pydantic-модель. | ||
| ## Проверка сгенерированной документации | ||
| Вы можете посмотреть объявленные cookies в графическом интерфейсе Документации по пути `/docs`: | ||
| <div class="screenshot"> | ||
| <img src="/img/tutorial/cookie-param-models/image01.png"> | ||
| </div> | ||
| /// info | Дополнительная информация | ||
| Имейте в виду, что, поскольку **браузеры обрабатывают cookies** особым образом и под капотом, они **не** позволят **JavaScript** легко получить доступ к ним. | ||
| Если вы перейдёте к **графическому интерфейсу документации API** по пути `/docs`, то сможете увидеть **документацию** по cookies для ваших *операций путей*. | ||
| Но даже если вы **заполните данные** и нажмёте "Execute", поскольку графический интерфейс Документации работает с **JavaScript**, cookies не будут отправлены, и вы увидите сообщение об **ошибке** как будто не указывали никаких значений. | ||
| /// | ||
| ## Запрет дополнительных cookies | ||
| В некоторых случаях (не особо часто встречающихся) вам может понадобиться **ограничить** cookies, которые вы хотите получать. | ||
| Теперь ваш API сам решает, <abbr title="Это шутка, на всякий случай. Это не имеет никакого отношения к согласию на использование cookie, но забавно, что даже API теперь может отклонять несчастные cookies. Съешьте печеньку. 🍪">принимать ли cookies</abbr>. 🤪🍪 | ||
| Вы можете сконфигурировать Pydantic-модель так, чтобы запретить (`forbid`) любые дополнительные (`extra`) поля: | ||
| {* ../../docs_src/cookie_param_models/tutorial002_an_py39.py hl[10] *} | ||
| Если клиент попробует отправить **дополнительные cookies**, то в ответ он получит **ошибку**. | ||
| Бедные баннеры cookies, они всеми силами пытаются получить ваше согласие — и всё ради того, чтобы <abbr title="Это ещё одна шутка. Не обращайте на меня внимания. Выпейте кофе со своей печенькой. ☕">API его отклонил</abbr>. 🍪 | ||
| Например, если клиент попытается отправить cookie `santa_tracker` со значением `good-list-please`, то в ответ он получит **ошибку**, сообщающую ему, что cookie `santa_tracker` <abbr title="Санта не одобряет пропажу печенья. 🎅 Ладно, больше никаких шуток про печенье.">не разрешён</abbr>: | ||
| ```json | ||
| { | ||
| "detail": [ | ||
| { | ||
| "type": "extra_forbidden", | ||
| "loc": ["cookie", "santa_tracker"], | ||
| "msg": "Extra inputs are not permitted", | ||
| "input": "good-list-please" | ||
| } | ||
| ] | ||
| } | ||
| ``` | ||
| ## Заключение | ||
| Вы можете использовать **Pydantic-модели** для объявления <abbr title="Съешьте последнюю печеньку, прежде чем уйти. 🍪">**cookies**</abbr> в **FastAPI**. 😎 |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.