Compare commits

...

19 Commits

Author SHA1 Message Date
Hasan Sezer Taşan b48d429dcb
Merge branch 'tiangolo:master' into tr/advanced/index.md 2024-06-01 22:19:15 +03:00
hasansezertasan 33d29056b1 Fix 2024-06-01 22:16:02 +03:00
hasansezertasan d7730f397c Restate 2024-06-01 22:12:35 +03:00
hasansezertasan bfd4329123 Remove extra line. 2024-06-01 22:11:02 +03:00
hasansezertasan d4972d532e Upgrade 2024-06-01 22:07:57 +03:00
github-actions 563b355a75 📝 Update release notes 2024-05-31 02:38:23 +00:00
Sebastián Ramírez ab8974ef04
📝 Tweak intro docs about `Annotated` and `Query()` params (#11664) 2024-05-30 21:38:05 -05:00
github-actions 995bd43619 📝 Update release notes 2024-05-30 13:28:41 +00:00
Sebastián Ramírez 803b9fca98
🔧 Add sponsor Kong (#11662) 2024-05-30 08:28:20 -05:00
github-actions ba1ac2b1f6 📝 Update release notes 2024-05-28 14:06:23 +00:00
Hasan Sezer Taşan a751cdd17f
🌐 Add Turkish translation for `docs/tr/docs/deployment/cloud.md` (#11610) 2024-05-28 09:05:55 -05:00
github-actions 8b4ce06065 📝 Update release notes 2024-05-27 16:23:10 +00:00
github-actions d523f7f340 📝 Update release notes 2024-05-27 16:22:14 +00:00
github-actions aadc3e7dc1 📝 Update release notes 2024-05-27 16:21:46 +00:00
Hasan Sezer Taşan a8a3971a99
🌐 Add Turkish translation for `docs/tr/docs/advanced/security/index.md` (#11609) 2024-05-27 11:21:37 -05:00
Hasan Sezer Taşan 59b17ce804
🌐 Add Turkish translation for `docs/tr/docs/advanced/testing-websockets.md` (#11608) 2024-05-27 11:21:03 -05:00
Hasan Sezer Taşan 54d0be2388
🌐 Add Turkish translation for `docs/tr/docs/how-to/general.md` (#11607) 2024-05-27 11:20:52 -05:00
github-actions 36269edf6a 📝 Update release notes 2024-05-27 16:19:42 +00:00
chaoless f7a11bc0b4
🌐 Update Chinese translation for `docs/zh/docs/advanced/templates.md` (#11620) 2024-05-27 11:19:21 -05:00
14 changed files with 190 additions and 60 deletions

View File

@ -55,6 +55,7 @@ The key features are:
<a href="https://www.propelauth.com/?utm_source=fastapi&utm_campaign=1223&utm_medium=mainbadge" target="_blank" title="Auth, user management and more for your B2B product"><img src="https://fastapi.tiangolo.com/img/sponsors/propelauth.png"></a> <a href="https://www.propelauth.com/?utm_source=fastapi&utm_campaign=1223&utm_medium=mainbadge" target="_blank" title="Auth, user management and more for your B2B product"><img src="https://fastapi.tiangolo.com/img/sponsors/propelauth.png"></a>
<a href="https://www.withcoherence.com/?utm_medium=advertising&utm_source=fastapi&utm_campaign=banner%20january%2024" target="_blank" title="Coherence"><img src="https://fastapi.tiangolo.com/img/sponsors/coherence.png"></a> <a href="https://www.withcoherence.com/?utm_medium=advertising&utm_source=fastapi&utm_campaign=banner%20january%2024" target="_blank" title="Coherence"><img src="https://fastapi.tiangolo.com/img/sponsors/coherence.png"></a>
<a href="https://www.mongodb.com/developer/languages/python/python-quickstart-fastapi/?utm_campaign=fastapi_framework&utm_source=fastapi_sponsorship&utm_medium=web_referral" target="_blank" title="Simplify Full Stack Development with FastAPI & MongoDB"><img src="https://fastapi.tiangolo.com/img/sponsors/mongodb.png"></a> <a href="https://www.mongodb.com/developer/languages/python/python-quickstart-fastapi/?utm_campaign=fastapi_framework&utm_source=fastapi_sponsorship&utm_medium=web_referral" target="_blank" title="Simplify Full Stack Development with FastAPI & MongoDB"><img src="https://fastapi.tiangolo.com/img/sponsors/mongodb.png"></a>
<a href="https://konghq.com/products/kong-konnect/register?utm_medium=referral&utm_source=github&utm_campaign=platform&utm_content=fast-api" target="_blank" title="Kong Konnect - API management platform"><img src="https://fastapi.tiangolo.com/img/sponsors/kong.png"></a>
<a href="https://training.talkpython.fm/fastapi-courses" target="_blank" title="FastAPI video courses on demand from people you trust"><img src="https://fastapi.tiangolo.com/img/sponsors/talkpython-v2.jpg"></a> <a href="https://training.talkpython.fm/fastapi-courses" target="_blank" title="FastAPI video courses on demand from people you trust"><img src="https://fastapi.tiangolo.com/img/sponsors/talkpython-v2.jpg"></a>
<a href="https://github.com/deepset-ai/haystack/" target="_blank" title="Build powerful search from composable, open source building blocks"><img src="https://fastapi.tiangolo.com/img/sponsors/haystack-fastapi.svg"></a> <a href="https://github.com/deepset-ai/haystack/" target="_blank" title="Build powerful search from composable, open source building blocks"><img src="https://fastapi.tiangolo.com/img/sponsors/haystack-fastapi.svg"></a>
<a href="https://databento.com/" target="_blank" title="Pay as you go for market data"><img src="https://fastapi.tiangolo.com/img/sponsors/databento.svg"></a> <a href="https://databento.com/" target="_blank" title="Pay as you go for market data"><img src="https://fastapi.tiangolo.com/img/sponsors/databento.svg"></a>

View File

@ -26,6 +26,9 @@ gold:
- url: https://www.mongodb.com/developer/languages/python/python-quickstart-fastapi/?utm_campaign=fastapi_framework&utm_source=fastapi_sponsorship&utm_medium=web_referral - url: https://www.mongodb.com/developer/languages/python/python-quickstart-fastapi/?utm_campaign=fastapi_framework&utm_source=fastapi_sponsorship&utm_medium=web_referral
title: Simplify Full Stack Development with FastAPI & MongoDB title: Simplify Full Stack Development with FastAPI & MongoDB
img: https://fastapi.tiangolo.com/img/sponsors/mongodb.png img: https://fastapi.tiangolo.com/img/sponsors/mongodb.png
- url: https://konghq.com/products/kong-konnect/register?utm_medium=referral&utm_source=github&utm_campaign=platform&utm_content=fast-api
title: Kong Konnect - API management platform
img: https://fastapi.tiangolo.com/img/sponsors/kong.png
silver: silver:
- url: https://training.talkpython.fm/fastapi-courses - url: https://training.talkpython.fm/fastapi-courses
title: FastAPI video courses on demand from people you trust title: FastAPI video courses on demand from people you trust

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

View File

@ -476,7 +476,7 @@ You will see a lot more of all this in practice in the [Tutorial - User Guide](t
## Type Hints with Metadata Annotations ## Type Hints with Metadata Annotations
Python also has a feature that allows putting **additional metadata** in these type hints using `Annotated`. Python also has a feature that allows putting **additional <abbr title="Data about the data, in this case, information about the type, e.g. a description.">metadata</abbr>** in these type hints using `Annotated`.
=== "Python 3.9+" === "Python 3.9+"

View File

@ -15,6 +15,7 @@ hide:
### Docs ### Docs
* 📝 Tweak intro docs about `Annotated` and `Query()` params. PR [#11664](https://github.com/tiangolo/fastapi/pull/11664) by [@tiangolo](https://github.com/tiangolo).
* 📝 Update JWT auth documentation to use PyJWT instead of pyhon-jose. PR [#11589](https://github.com/tiangolo/fastapi/pull/11589) by [@estebanx64](https://github.com/estebanx64). * 📝 Update JWT auth documentation to use PyJWT instead of pyhon-jose. PR [#11589](https://github.com/tiangolo/fastapi/pull/11589) by [@estebanx64](https://github.com/estebanx64).
* 📝 Update docs. PR [#11603](https://github.com/tiangolo/fastapi/pull/11603) by [@alejsdev](https://github.com/alejsdev). * 📝 Update docs. PR [#11603](https://github.com/tiangolo/fastapi/pull/11603) by [@alejsdev](https://github.com/alejsdev).
* ✏️ Fix typo: convert every 're-use' to 'reuse'.. PR [#11598](https://github.com/tiangolo/fastapi/pull/11598) by [@hasansezertasan](https://github.com/hasansezertasan). * ✏️ Fix typo: convert every 're-use' to 'reuse'.. PR [#11598](https://github.com/tiangolo/fastapi/pull/11598) by [@hasansezertasan](https://github.com/hasansezertasan).
@ -23,6 +24,11 @@ hide:
### Translations ### Translations
* 🌐 Add Turkish translation for `docs/tr/docs/deployment/cloud.md`. PR [#11610](https://github.com/tiangolo/fastapi/pull/11610) by [@hasansezertasan](https://github.com/hasansezertasan).
* 🌐 Add Turkish translation for `docs/tr/docs/advanced/security/index.md`. PR [#11609](https://github.com/tiangolo/fastapi/pull/11609) by [@hasansezertasan](https://github.com/hasansezertasan).
* 🌐 Add Turkish translation for `docs/tr/docs/advanced/testing-websockets.md`. PR [#11608](https://github.com/tiangolo/fastapi/pull/11608) by [@hasansezertasan](https://github.com/hasansezertasan).
* 🌐 Add Turkish translation for `docs/tr/docs/how-to/general.md`. PR [#11607](https://github.com/tiangolo/fastapi/pull/11607) by [@hasansezertasan](https://github.com/hasansezertasan).
* 🌐 Update Chinese translation for `docs/zh/docs/advanced/templates.md`. PR [#11620](https://github.com/tiangolo/fastapi/pull/11620) by [@chaoless](https://github.com/chaoless).
* 🌐 Add Turkish translation for `docs/tr/docs/deployment/index.md`. PR [#11605](https://github.com/tiangolo/fastapi/pull/11605) by [@hasansezertasan](https://github.com/hasansezertasan). * 🌐 Add Turkish translation for `docs/tr/docs/deployment/index.md`. PR [#11605](https://github.com/tiangolo/fastapi/pull/11605) by [@hasansezertasan](https://github.com/hasansezertasan).
* 🌐 Add Turkish translation for `docs/tr/docs/tutorial/static-files.md`. PR [#11599](https://github.com/tiangolo/fastapi/pull/11599) by [@hasansezertasan](https://github.com/hasansezertasan). * 🌐 Add Turkish translation for `docs/tr/docs/tutorial/static-files.md`. PR [#11599](https://github.com/tiangolo/fastapi/pull/11599) by [@hasansezertasan](https://github.com/hasansezertasan).
* 🌐 Polish translation for `docs/pl/docs/fastapi-people.md`. PR [#10196](https://github.com/tiangolo/fastapi/pull/10196) by [@isulim](https://github.com/isulim). * 🌐 Polish translation for `docs/pl/docs/fastapi-people.md`. PR [#10196](https://github.com/tiangolo/fastapi/pull/10196) by [@isulim](https://github.com/isulim).
@ -35,6 +41,7 @@ hide:
### Internal ### Internal
* 🔧 Add sponsor Kong. PR [#11662](https://github.com/tiangolo/fastapi/pull/11662) by [@tiangolo](https://github.com/tiangolo).
* 👷 Update Smokeshow, fix sync download artifact and smokeshow configs. PR [#11563](https://github.com/tiangolo/fastapi/pull/11563) by [@tiangolo](https://github.com/tiangolo). * 👷 Update Smokeshow, fix sync download artifact and smokeshow configs. PR [#11563](https://github.com/tiangolo/fastapi/pull/11563) by [@tiangolo](https://github.com/tiangolo).
* 👷 Update Smokeshow download artifact GitHub Action. PR [#11562](https://github.com/tiangolo/fastapi/pull/11562) by [@tiangolo](https://github.com/tiangolo). * 👷 Update Smokeshow download artifact GitHub Action. PR [#11562](https://github.com/tiangolo/fastapi/pull/11562) by [@tiangolo](https://github.com/tiangolo).
* 👷 Update GitHub actions to download and upload artifacts to v4, for docs and coverage. PR [#11550](https://github.com/tiangolo/fastapi/pull/11550) by [@tamird](https://github.com/tamird). * 👷 Update GitHub actions to download and upload artifacts to v4, for docs and coverage. PR [#11550](https://github.com/tiangolo/fastapi/pull/11550) by [@tamird](https://github.com/tamird).

View File

@ -99,7 +99,7 @@ Now let's jump to the fun stuff. 🎉
## Add `Query` to `Annotated` in the `q` parameter ## Add `Query` to `Annotated` in the `q` parameter
Now that we have this `Annotated` where we can put more metadata, add `Query` to it, and set the parameter `max_length` to 50: Now that we have this `Annotated` where we can put more information (in this case some additional validation), add `Query` inside of `Annotated`, and set the parameter `max_length` to `50`:
=== "Python 3.10+" === "Python 3.10+"
@ -115,7 +115,11 @@ Now that we have this `Annotated` where we can put more metadata, add `Query` to
Notice that the default value is still `None`, so the parameter is still optional. Notice that the default value is still `None`, so the parameter is still optional.
But now, having `Query(max_length=50)` inside of `Annotated`, we are telling FastAPI that we want it to extract this value from the query parameters (this would have been the default anyway 🤷) and that we want to have **additional validation** for this value (that's why we do this, to get the additional validation). 😎 But now, having `Query(max_length=50)` inside of `Annotated`, we are telling FastAPI that we want it to have **additional validation** for this value, we want it to have maximum 50 characters. 😎
!!! tip
Here we are using `Query()` because this is a **query parameter**. Later we will see others like `Path()`, `Body()`, `Header()`, and `Cookie()`, that also accept the same arguments as `Query()`.
FastAPI will now: FastAPI will now:

View File

@ -76,6 +76,12 @@
<img class="sponsor-image" src="/img/sponsors/mongodb-banner.png" /> <img class="sponsor-image" src="/img/sponsors/mongodb-banner.png" />
</a> </a>
</div> </div>
<div class="item">
<a title="Kong Konnect - API management platform" style="display: block; position: relative;" href="https://konghq.com/products/kong-konnect/register?utm_medium=referral&utm_source=github&utm_campaign=platform&utm_content=fast-api" target="_blank">
<span class="sponsor-badge">sponsor</span>
<img class="sponsor-image" src="/img/sponsors/kong-banner.png" />
</a>
</div>
</div> </div>
</div> </div>
{% endblock %} {% endblock %}

View File

@ -1,35 +1,33 @@
# Gelişmiş Kullanıcı Rehberi # Gelişmiş Kullanıcı Rehberi
## Ek Özellikler ## Ek Özellikler
[Tutorial - User Guide](../tutorial/index.md){.internal-link target=_blank} sayfası **FastAPI**'ın tüm ana özelliklerini tanıtmaya yetecektir. [Tutorial - User Guide](../tutorial/index.md){.internal-link target=_blank} sayfası **FastAPI**'ın tüm ana özelliklerini tanıtmaya yetecektir.
İlerleyen bölümlerde diğer seçenekler, konfigürasyonlar ve ek özellikleri göreceğiz. İlerleyen bölümlerde diğer seçenekler, konfigürasyonlar ve ek özellikleri göreceğiz.
!!! tip "İpucu" !!! tip "İpucu"
Sonraki bölümler **mutlaka "gelişmiş" olmak zorunda değildir**. Sonraki bölümler **mutlaka "gelişmiş" olmak zorunda değildir**.
Kullanım şeklinize bağlı olarak, çözümünüz bu bölümlerden birinde olabilir. Kullanım şeklinize bağlı olarak, çözümünüz bu bölümlerden birinde olabilir.
## Önce Öğreticiyi Okuyun ## Önce Öğreticiyi Okuyun
[Tutorial - User Guide](../tutorial/index.md){.internal-link target=_blank} sayfasındaki bilgilerle **FastAPI**'nın çoğu özelliğini kullanabilirsiniz. [Tutorial - User Guide](../tutorial/index.md){.internal-link target=_blank} sayfasındaki bilgilerle **FastAPI**'nın çoğu özelliğini kullanabilirsiniz.
Sonraki bölümler bu sayfayı okuduğunuzu ve bu ana fikirleri bildiğinizi varsayarak hazırlanmıştır. Sonraki bölümler bu sayfayı okuduğunuzu ve bu ana fikirleri bildiğinizi varsayarak hazırlanmıştır.
## Diğer Kurslar ## Diğer Kurslar
[Tutorial - User Guide](../tutorial/index.md){.internal-link target=_blank} sayfasının ve bu **Gelişmiş Kullanıcı Rehberi**'nin öğretici olmak amacıyla (bir kitap gibi) yazılmış olmasına ve **FastAPI'ı öğrenmek** için yeterli olmasına rağmen, ek kurslarla desteklemek isteyebilirsiniz. [Tutorial - User Guide](../tutorial/index.md){.internal-link target=_blank} sayfasının ve bu **Gelişmiş Kullanıcı Rehberi**'nin öğretici olmak amacıyla (bir kitap gibi) yazılmış olmasına ve **FastAPI'ı öğrenmek** için yeterli olmasına rağmen, ek kurslarla desteklemek isteyebilirsiniz.
Belki de öğrenme tarzınıza daha iyi uyduğu için başka kursları tercih edebilirsiniz. Belki de öğrenme tarzınıza daha iyi uyduğu için başka kursları tercih edebilirsiniz.
Bazı kurs sağlayıcıları ✨ [**FastAPI destekçileridir**](../help-fastapi.md#sponsor-the-author){.internal-link target=_blank} ✨, bu FastAPI ve **ekosisteminin** sürekli ve sağlıklı bir şekilde **gelişmesini** sağlar. Bazı kurs sağlayıcıları ✨ [**FastAPI destekçileridir**](../help-fastapi.md#sponsor-the-author){.internal-link target=_blank} ✨, bu FastAPI ve **ekosisteminin** sürekli ve sağlıklı bir şekilde **gelişmesini** sağlar.
Ayrıca, size **iyi bir öğrenme deneyimi** sağlamakla kalmayıp, **iyi ve sağlıklı bir framework** olan FastAPI'a bağlılıklarını gösterir. Ayrıca, size **iyi bir öğrenme deneyimi** sağlamakla kalmayıp, **iyi ve sağlıklı bir framework** olan FastAPI'a ve ve **topluluğuna** (yani size) olan gerçek bağlılıklarını gösterir.
Ve bu onların FastAPI'a ve onun **topluluğuna** (yani size) olan gerçek bağlılıklarını gösterir; çünkü size yalnızca **iyi bir öğrenme deneyimi** sunmak değil, aynı zamanda FastAPI'ın **iyi ve sağlıklı bir çerçeveye** olduğunuzdan emin olmak da istiyorlar. 🙇 Onların kurslarını denemek isteyebilirsiniz:
Onların kurslarını denemek isteyebilirsiniz: * <a href="https://training.talkpython.fm/fastapi-courses" class="external-link" target="_blank">Talk Python Training</a>
* <a href="https://testdriven.io/courses/tdd-fastapi/" class="external-link" target="_blank">Test-Driven Development</a>
* <a href="https://training.talkpython.fm/fastapi-courses" class="external-link" target="_blank">Talk Python Training</a>
* <a href="https://testdriven.io/courses/tdd-fastapi/" class="external-link" target="_blank">Test-Driven Development</a>

View File

@ -0,0 +1,16 @@
# Gelişmiş Güvenlik
## Ek Özellikler
[Tutorial - User Guide: Security](../../tutorial/security/index.md){.internal-link target=_blank} sayfasında ele alınanların dışında güvenlikle ilgili bazı ek özellikler vardır.
!!! tip "İpucu"
Sonraki bölümler **mutlaka "gelişmiş" olmak zorunda değildir**.
Kullanım şeklinize bağlı olarak, çözümünüz bu bölümlerden birinde olabilir.
## Önce Öğreticiyi Okuyun
Sonraki bölümler [Tutorial - User Guide: Security](../../tutorial/security/index.md){.internal-link target=_blank} sayfasını okuduğunuzu varsayarak hazırlanmıştır.
Bu bölümler aynı kavramlara dayanır, ancak bazı ek işlevsellikler sağlar.

View File

@ -0,0 +1,12 @@
# WebSockets'i Test Etmek
WebSockets testi yapmak için `TestClient`'ı kullanabilirsiniz.
Bu işlem için, `TestClient`'ı bir `with` ifadesinde kullanarak WebSocket'e bağlanabilirsiniz:
```Python hl_lines="27-31"
{!../../../docs_src/app_testing/tutorial002.py!}
```
!!! note "Not"
Daha fazla detay için Starlette'in <a href="https://www.starlette.io/staticfiles/" class="external-link" target="_blank">Websockets'i Test Etmek</a> dokümantasyonunu inceleyin.

View File

@ -0,0 +1,17 @@
# FastAPI Uygulamasını Bulut Sağlayıcılar Üzerinde Yayınlama
FastAPI uygulamasını yayınlamak için hemen hemen **herhangi bir bulut sağlayıcıyı** kullanabilirsiniz.
Büyük bulut sağlayıcıların çoğu FastAPI uygulamasını yayınlamak için kılavuzlara sahiptir.
## Bulut Sağlayıcılar - Sponsorlar
Bazı bulut sağlayıcılar ✨ [**FastAPI destekçileridir**](../help-fastapi.md#sponsor-the-author){.internal-link target=_blank} ✨, bu FastAPI ve **ekosisteminin** sürekli ve sağlıklı bir şekilde **gelişmesini** sağlar.
Ayrıca, size **iyi servisler** sağlamakla kalmayıp, **iyi ve sağlıklı bir framework** olan FastAPI'a bağlılıklarını gösterir.
Bu hizmetleri denemek ve kılavuzlarını incelemek isteyebilirsiniz:
* <a href="https://docs.platform.sh/languages/python.html?utm_source=fastapi-signup&utm_medium=banner&utm_campaign=FastAPI-signup-June-2023" class="external-link" target="_blank">Platform.sh</a>
* <a href="https://docs.porter.run/language-specific-guides/fastapi" class="external-link" target="_blank">Porter</a>
* <a href="https://docs.withcoherence.com/docs/configuration/frameworks?utm_medium=advertising&utm_source=fastapi&utm_campaign=banner%20january%2024#fast-api-example" class="external-link" target="_blank">Coherence</a>

View File

@ -0,0 +1,39 @@
# Genel - Nasıl Yapılır - Tarifler
Bu sayfada genel ve sıkça sorulan sorular için dokümantasyonun diğer sayfalarına yönlendirmeler bulunmaktadır.
## Veri Filtreleme - Güvenlik
Döndürmeniz gereken veriden fazlasını döndürmediğinizden emin olmak için, [Tutorial - Response Model - Return Type](../tutorial/response-model.md){.internal-link target=_blank} sayfasını okuyun.
## Dokümantasyon Etiketleri - OpenAPI
*Yol operasyonlarınıza* etiketler ekleyerek dokümantasyon arayüzünde gruplar halinde görünmesini sağlamak için, [Tutorial - Path Operation Configurations - Tags](../tutorial/path-operation-configuration.md#tags){.internal-link target=_blank} sayfasını okuyun.
## Dokümantasyon Özeti ve Açıklaması - OpenAPI
*Yol operasyonlarınıza* özet ve açıklama ekleyip dokümantasyon arayüzünde görünmesini sağlamak için, [Tutorial - Path Operation Configurations - Summary and Description](../tutorial/path-operation-configuration.md#summary-and-description){.internal-link target=_blank} sayfasını okuyun.
## Yanıt Açıklaması Dokümantasyonu - OpenAPI
Dokümantasyon arayüzünde yer alan yanıt açıklamasını tanımlamak için, [Tutorial - Path Operation Configurations - Response description](../tutorial/path-operation-configuration.md#response-description){.internal-link target=_blank} sayfasını okuyun.
## *Yol Operasyonunu* Kullanımdan Kaldırma - OpenAPI
Bir *yol işlemi*ni kullanımdan kaldırmak ve bunu dokümantasyon arayüzünde göstermek için, [Tutorial - Path Operation Configurations - Deprecation](../tutorial/path-operation-configuration.md#deprecate-a-path-operation){.internal-link target=_blank} sayfasını okuyun.
## Herhangi Bir Veriyi JSON Uyumlu Hale Getirme
Herhangi bir veriyi JSON uyumlu hale getirmek için, [Tutorial - JSON Compatible Encoder](../tutorial/encoder.md){.internal-link target=_blank} sayfasını okuyun.
## OpenAPI Meta Verileri - Dokümantasyon
OpenAPI şemanıza lisans, sürüm, iletişim vb. meta veriler eklemek için, [Tutorial - Metadata and Docs URLs](../tutorial/metadata.md){.internal-link target=_blank} sayfasını okuyun.
## OpenAPI Bağlantı Özelleştirme
OpenAPI bağlantısını özelleştirmek (veya kaldırmak) için, [Tutorial - Metadata and Docs URLs](../tutorial/metadata.md#openapi-url){.internal-link target=_blank} sayfasını okuyun.
## OpenAPI Dokümantasyon Bağlantıları
Dokümantasyonu arayüzünde kullanılan bağlantıları güncellemek için, [Tutorial - Metadata and Docs URLs](../tutorial/metadata.md#docs-urls){.internal-link target=_blank} sayfasını okuyun.

View File

@ -20,24 +20,12 @@ $ pip install jinja2
</div> </div>
如需使用静态文件,还要安装 `aiofiles`
<div class="termy">
```console
$ pip install aiofiles
---> 100%
```
</div>
## 使用 `Jinja2Templates` ## 使用 `Jinja2Templates`
* 导入 `Jinja2Templates` * 导入 `Jinja2Templates`
* 创建可复用的 `templates` 对象 * 创建可复用的 `templates` 对象
* 在返回模板的*路径操作*中声明 `Request` 参数 * 在返回模板的*路径操作*中声明 `Request` 参数
* 使用 `templates` 渲染并返回 `TemplateResponse` 以键值对方式在 Jinja2 的 **context** 中传递 `request` * 使用 `templates` 渲染并返回 `TemplateResponse` 传递模板的名称、request对象以及一个包含多个键值对用于Jinja2模板的"context"字典,
```Python hl_lines="4 11 15-16" ```Python hl_lines="4 11 15-16"
{!../../../docs_src/templates/tutorial001.py!} {!../../../docs_src/templates/tutorial001.py!}
@ -45,7 +33,8 @@ $ pip install aiofiles
!!! note "笔记" !!! note "笔记"
注意,必须为 Jinja2 以键值对方式在上下文中传递 `request`。因此,还要在*路径操作*中声明。 在FastAPI 0.108.0Starlette 0.29.0之前,`name`是第一个参数。
并且,在此之前,`request`对象是作为context的一部分以键值对的形式传递的。
!!! tip "提示" !!! tip "提示"
@ -65,30 +54,68 @@ $ pip install aiofiles
{!../../../docs_src/templates/templates/item.html!} {!../../../docs_src/templates/templates/item.html!}
``` ```
它会显示从 **context** 字典中提取的 `id` ### 模板上下文
在包含如下语句的html中:
{% raw %}
```jinja
Item ID: {{ id }}
```
{% endraw %}
...这将显示你从"context"字典传递的 `id`:
```Python ```Python
{"request": request, "id": id} {"id": id}
```
例如。当ID为 `42`时, 会渲染成:
```html
Item ID: 42
```
### 模板 `url_for` 参数
你还可以在模板内使用 `url_for()`,其参数与*路径操作函数*的参数相同.
所以,该部分:
{% raw %}
```jinja
<a href="{{ url_for('read_item', id=id) }}">
```
{% endraw %}
...将生成一个与处理*路径操作函数* `read_item(id=id)`的URL相同的链接
例如。当ID为 `42`时, 会渲染成:
```html
<a href="/items/42">
``` ```
## 模板与静态文件 ## 模板与静态文件
在模板内部使用 `url_for()`,例如,与挂载的 `StaticFiles` 一起使用。 你还可以在模板内部将 `url_for()`用于静态文件,例如你挂载的 `name="static"``StaticFiles`
```jinja hl_lines="4" ```jinja hl_lines="4"
{!../../../docs_src/templates/templates/item.html!} {!../../../docs_src/templates/templates/item.html!}
``` ```
本例中,使用 `url_for()` 为模板添加 CSS 文件 `static/styles.css` 链接: 本例中,它将链接到 `static/styles.css`中的CSS文件
```CSS hl_lines="4" ```CSS hl_lines="4"
{!../../../docs_src/templates/static/styles.css!} {!../../../docs_src/templates/static/styles.css!}
``` ```
因为使用了 `StaticFiles` **FastAPI** 应用自动提供位于 URL `/static/styles.css` 因为使用了 `StaticFiles` **FastAPI** 应用会自动提供位于 URL `/static/styles.css`的 CSS 文件。
的 CSS 文件。
## 更多说明 ## 更多说明
包括测试模板等更多详情,请参阅 <a href="https://www.starlette.io/templates/" class="external-link" target="_blank">Starlette 官档 - 模板</a> 包括测试模板等更多详情,请参阅 <a href="https://www.starlette.io/templates/" class="external-link" target="_blank">Starlette 官方文档 - 模板</a>