From 7122687f25fab2e4daea267b90423bde9694f5b3 Mon Sep 17 00:00:00 2001 From: "T. Tokusumi" <41147016+tokusumi@users.noreply.github.com> Date: Mon, 8 Feb 2021 02:38:10 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=90=20Add=20Japanese=20translation=20f?= =?UTF-8?q?or=20Tutorial=20-=20Static=20files=20(#2260)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Taki Komiyama <39375566+komtaki@users.noreply.github.com> Co-authored-by: Sho Nakamura Co-authored-by: Sebastián Ramírez --- docs/ja/docs/tutorial/static-files.md | 53 +++++++++++++++++++++++++++ docs/ja/mkdocs.yml | 1 + 2 files changed, 54 insertions(+) create mode 100644 docs/ja/docs/tutorial/static-files.md diff --git a/docs/ja/docs/tutorial/static-files.md b/docs/ja/docs/tutorial/static-files.md new file mode 100644 index 000000000..fcc3ba924 --- /dev/null +++ b/docs/ja/docs/tutorial/static-files.md @@ -0,0 +1,53 @@ +# 静的ファイル + +`StaticFiles` を使用して、ディレクトリから静的ファイルを自動的に提供できます。 + +## `aiofiles` をインストール + +まず、`aiofiles` をインストールする必要があります: + +
+ +```console +$ pip install aiofiles + +---> 100% +``` + +
+ +## `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** が内部で使用できる名前を付けます。 + +これらのパラメータはすべて「`静的`」とは異なる場合があり、独自のアプリケーションのニーズと詳細に合わせて調整します。 + +## より詳しい情報 + +詳細とオプションについては、Starletteの静的ファイルに関するドキュメントを確認してください。 diff --git a/docs/ja/mkdocs.yml b/docs/ja/mkdocs.yml index fabf9d46c..b3714bcde 100644 --- a/docs/ja/mkdocs.yml +++ b/docs/ja/mkdocs.yml @@ -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 - 高度なユーザーガイド: