mirror of https://github.com/tiangolo/fastapi.git
🌐 Add Japanese translation for Tutorial - Static files (#2260)
Co-authored-by: Taki Komiyama <39375566+komtaki@users.noreply.github.com> Co-authored-by: Sho Nakamura <sh0nk.developer@gmail.com> Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
This commit is contained in:
parent
af6fcf1413
commit
7122687f25
|
|
@ -0,0 +1,53 @@
|
|||
# 静的ファイル
|
||||
|
||||
`StaticFiles` を使用して、ディレクトリから静的ファイルを自動的に提供できます。
|
||||
|
||||
## `aiofiles` をインストール
|
||||
|
||||
まず、`aiofiles` をインストールする必要があります:
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
$ pip install aiofiles
|
||||
|
||||
---> 100%
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
## `StaticFiles` の使用
|
||||
|
||||
* `StaticFiles` をインポート。
|
||||
* `StaticFiles()` インスタンスを生成し、特定のパスに「マウント」。
|
||||
|
||||
```Python hl_lines="2 6"
|
||||
{!../../../docs_src/static_files/tutorial001.py!}
|
||||
```
|
||||
|
||||
!!! note "技術詳細"
|
||||
`from starlette.staticfiles import StaticFiles` も使用できます。
|
||||
|
||||
**FastAPI**は、開発者の利便性のために、`starlette.staticfiles` と同じ `fastapi.staticfiles` を提供します。しかし、実際にはStarletteから直接渡されています。
|
||||
|
||||
### 「マウント」とは
|
||||
|
||||
「マウント」とは、特定のパスに完全な「独立した」アプリケーションを追加することを意味します。これにより、すべてのサブパスの処理がなされます。
|
||||
|
||||
これは、マウントされたアプリケーションが完全に独立しているため、`APIRouter` とは異なります。メインアプリケーションのOpenAPIとドキュメントには、マウントされたアプリケーションの内容などは含まれません。
|
||||
|
||||
これについて詳しくは、**高度なユーザーガイド** をご覧ください。
|
||||
|
||||
## 詳細
|
||||
|
||||
最初の `"/static"` は、この「サブアプリケーション」が「マウント」されるサブパスを指します。したがって、`"/static"` から始まるパスはすべてサブアプリケーションによって処理されます。
|
||||
|
||||
`directory="static"` は、静的ファイルを含むディレクトリの名前を指します。
|
||||
|
||||
`name="static"` は、**FastAPI** が内部で使用できる名前を付けます。
|
||||
|
||||
これらのパラメータはすべて「`静的`」とは異なる場合があり、独自のアプリケーションのニーズと詳細に合わせて調整します。
|
||||
|
||||
## より詳しい情報
|
||||
|
||||
詳細とオプションについては、<a href="https://www.starlette.io/staticfiles/" class="external-link" target="_blank">Starletteの静的ファイルに関するドキュメント</a>を確認してください。
|
||||
|
|
@ -67,6 +67,7 @@ nav:
|
|||
- tutorial/security/first-steps.md
|
||||
- tutorial/middleware.md
|
||||
- tutorial/cors.md
|
||||
- tutorial/static-files.md
|
||||
- tutorial/testing.md
|
||||
- tutorial/debugging.md
|
||||
- 高度なユーザーガイド:
|
||||
|
|
|
|||
Loading…
Reference in New Issue