静的ファイル - StaticFiles
¶
StaticFiles
クラスを使用して、JavaScript、CSS、画像などの静的ファイルを配信できます。
静的ファイルに関するFastAPIドキュメントで詳細を確認してください。
fastapi.staticfiles
から直接インポートできます。
from fastapi.staticfiles import StaticFiles
fastapi.staticfiles.StaticFiles ¶
StaticFiles(
*,
directory=None,
packages=None,
html=False,
check_dir=True,
follow_symlink=False
)
パラメータ | 説明 |
---|---|
directory
|
型: |
packages
|
型: |
html
|
型: |
check_dir
|
型: |
follow_symlink
|
型: |
starlette/staticfiles.py
のソースコード
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
|
get_directories ¶
get_directories(directory=None, packages=None)
directory
引数とpackages
引数を指定して、静的ファイルを配信するために使用するすべてのディレクトリのリストを返します。
パラメータ | 説明 |
---|---|
directory
|
型: |
packages
|
型: |
starlette/staticfiles.py
のソースコード
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
|
get_path ¶
get_path(scope)
WSGIスコープを指定して、OS固有のパスセパレータを使用し、「..」、「.」コンポーネントを削除した、配信するpath
文字列を返します。
パラメータ | 説明 |
---|---|
scope
|
型: |
starlette/staticfiles.py
のソースコード
101 102 103 104 105 106 107 |
|
get_response async
¶
get_response(path, scope)
着信パス、メソッド、リクエストヘッダーを指定して、HTTPレスポンスを返します。
パラメータ | 説明 |
---|---|
path
|
型: |
scope
|
型: |
starlette/staticfiles.py
のソースコード
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
|
lookup_path ¶
lookup_path(path)
パラメータ | 説明 |
---|---|
path
|
型: |
starlette/staticfiles.py
のソースコード
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
|
file_response ¶
file_response(
full_path, stat_result, scope, status_code=200
)
パラメータ | 説明 |
---|---|
full_path
|
型: |
stat_result
|
型: |
scope
|
型: |
status_code
|
型: |
starlette/staticfiles.py
のソースコード
169 170 171 172 173 174 175 176 177 178 179 180 181 |
|
check_config async
¶
check_config()
StaticFilesが実際にディレクトリを指しているかどうかを一度限りの構成チェックを実行して、404レスポンスを返すだけでなく、明瞭なエラーを発生させることができます。
starlette/staticfiles.py
のソースコード
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
|
is_not_modified ¶
is_not_modified(response_headers, request_headers)
リクエストヘッダーとレスポンスヘッダーを指定して、HTTP「変更なし」レスポンスを代わりに返すことができる場合にTrue
を返します。
パラメータ | 説明 |
---|---|
response_headers
|
型: |
request_headers
|
型: |
starlette/staticfiles.py
のソースコード
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
|