コンテンツにスキップ
per page, with , order by , clip by
Results of 1 - 10 of about 25 for content (0.004 sec.)
Advanced Dependencies 14612
Advanced Dependencies Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . Parameterized dependencies All the dependencies we have seen are a fixed function or class. B ... tions or classes. Let's imagine that we want to have a dependency that checks if the query parameter q contains some fixed content. But we want to be able to parameterize that fixed content. A "callable" instance In Python there's a way to make an insta ... thod __call__ : Python 3.9+ from typing import Annotated from fastapi import Depends , FastAPI app = FastAPI () class FixedContentQueryChecker : def __init__ ( self , fixed_content : str ): self . fixed_content = fixed_content def __call__ ( self , q : ... str = "" ): if q : return self . fixed_content in q return False checker = FixedContentQueryChecker ( "bar" ) @app . get ( "/query-checker/" ) async def read_query_check ...
https://man.mtool.work/fastapi/0.115/advanced/advanced-dependencies/
Request Files 10577
Request Files Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . You can define files to be uploaded by the client using File . Info To receive uploaded files, first ... the type of your path operation function parameter as bytes , FastAPI will read the file for you and you will receive the contents as bytes . Keep in mind that this means that the whole contents will be stored in memory. This will work well for small f ... loadFile has the following attributes: filename : A str with the original file name that was uploaded (e.g. myimage.jpg ). content_type : A str with the content type (MIME type / media type) (e.g. image/jpeg ). file : A SpooledTemporaryFile (a file-like ... would go to the start of the file. This is especially useful if you run await myfile.read() once and then need to read the contents again. close() : Closes the file. As all these methods are async methods, you need to "await" them. For example, inside o ...
https://man.mtool.work/fastapi/0.115/tutorial/request-files/
リクエストフォームとファイル 10461
リクエストフォームとファイル File と Form を同時に使うことでファイルとフォームフィールドを定義することができます。 情報 アップロードされたファイルやフォームデータを受信するには、まず python-multipart をインストールします。 例えば、 pip inst ... e (), fileb : UploadFile = File (), token : str = Form () ): return { "file_size" : len ( file ), "token" : token , "fileb_content_type" : fileb . content_type , } ? Other versions and variants Python 3.9+ Python 3.8+ from typing import Annotated from f ... ploadFile , File ()], token : Annotated [ str , Form ()], ): return { "file_size" : len ( file ), "token" : token , "fileb_content_type" : fileb . content_type , } from fastapi import FastAPI , File , Form , UploadFile from typing_extensions import Anno ... ploadFile , File ()], token : Annotated [ str , Form ()], ): return { "file_size" : len ( file ), "token" : token , "fileb_content_type" : fileb . content_type , } File と Form のパラメータの定義 ファイルやフォームのパラメータは Body や Query の場合と同 ...
https://man.mtool.work/fastapi/0.115/tutorial/request-forms-and-files/
カスタムレスポンス - HTML、ストリーム、ファイル、その他のレスポンス 9963
カスタムレスポンス - HTML、ストリーム、ファイル、その他のレスポンス デフォルトでは、 FastAPI は JSONResponse を使ってレスポンスを返します。 レスポンスを直接返す で見たように、 Response を直接返すことでこの挙動をオーバーライドできます。 しか ... 直接返すと、データは自動的に変換されず、ドキュメントも自動生成されません (例えば、生成されるOpenAPIの一部としてHTTPヘッダー Content-Type に特定の「メディアタイプ」を含めるなど) 。 しかし、 path operationデコレータ に、使いたい Response を宣言することもで ... パラメータ response_class は、レスポンスの「メディアタイプ」を定義するために利用することもできます。 この場合、HTTPヘッダー Content-Type には application/json がセットされます。 そして、OpenAPIにはそのようにドキュメントされます。 豆知識 ORJSONResponse は ... ス FastAPI からHTMLを直接返す場合は、 HTMLResponse を使います。 HTMLResponse をインポートする。 path operation のパラメータ content_type に HTMLResponse を渡す。 Python 3.8+ from fastapi import FastAPI from fastapi.responses import HTMLResponse app = Fas ...
https://man.mtool.work/fastapi/0.115/advanced/custom-response/
WebSocket 9381
WebSocket FastAPI で WebSocket が使用できます。 WebSockets のインストール まず WebSockets のインストールが必要です。 $ pip install websockets ---> 100% WebSocket クライアント 本番環境 本番環境では、React、Vue.js、Angularなどの最新のフレーム ... sage = function(event) { var messages = document.getElementById('messages') var message = document.createElement('li') var content = document.createTextNode(event.data) message.appendChild(content) messages.appendChild(message) }; function sendMessage(e ... sage = function(event) { var messages = document.getElementById('messages') var message = document.createElement('li') var content = document.createTextNode(event.data) message.appendChild(content) messages.appendChild(message) }; function sendMessage(e ... sage = function(event) { var messages = document.getElementById('messages') var message = document.createElement('li') var content = document.createTextNode(event.data) message.appendChild(content) messages.appendChild(message) }; function sendMessage(e ...
https://man.mtool.work/fastapi/0.115/advanced/websockets/
Additional Responses in OpenAPI 9232
Additional Responses in OpenAPI Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . Warning This is a rather advanced topic. If you are starting with FastAPI , you mig ... ose additional responses you have to make sure you return a Response like JSONResponse directly, with your status code and content. Additional Response with model You can pass to your path operation decorators a parameter responses . It receives a dict ... : if item_id == "foo" : return { "id" : "foo" , "value" : "there goes my hero" } return JSONResponse ( status_code = 404 , content = { "message" : "Item not found" }) Note Keep in mind that you have to return the JSONResponse directly. Info The model ke ... the Pydantic model from there, generate the JSON Schema, and put it in the correct place. The correct place is: In the key content , that has as value another JSON object ( dict ) that contains: A key with the media type, e.g. application/json , that co ...
https://man.mtool.work/fastapi/0.115/advanced/additional-responses/
Response Headers 8535
Response Headers Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . Use a Response parameter You can declare a parameter of type Response in your path operation funct ... import FastAPI from fastapi.responses import JSONResponse app = FastAPI () @app . get ( "/headers/" ) def get_headers (): content = { "message" : "Hello World" } headers = { "X-Cat-Dog" : "alone in the world" , "Content-Language" : "en-US" } return JSO ... NResponse ( content = content , headers = headers ) Technical Details You could also use from starlette.responses import Response or from star ...
https://man.mtool.work/fastapi/0.115/advanced/response-headers/
追加のステータスコード 8153
追加のステータスコード デフォルトでは、 FastAPI は JSONResponse を使ってレスポンスを返します。その JSONResponse の中には、 path operation が返した内容が入ります。 それは、デフォルトのステータスコードか、 path operation でセットしたものを利用 ... { "name" : name , "size" : size } items [ item_id ] = item return JSONResponse ( status_code = status . HTTP_201_CREATED , content = item ) ? Other versions and variants Python 3.10+ Python 3.9+ Python 3.8+ Python 3.10+ - non-Annotated from typing impor ... { "name" : name , "size" : size } items [ item_id ] = item return JSONResponse ( status_code = status . HTTP_201_CREATED , content = item ) from typing import Annotated , Union from fastapi import Body , FastAPI , status from fastapi.responses import JS ... { "name" : name , "size" : size } items [ item_id ] = item return JSONResponse ( status_code = status . HTTP_201_CREATED , content = item ) from typing import Union from fastapi import Body , FastAPI , status from fastapi.responses import JSONResponse f ...
https://man.mtool.work/fastapi/0.115/advanced/additional-status-codes/
Response Cookies 8119
Response Cookies Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . Use a Response parameter You can declare a parameter of type Response in your path operation funct ... mport FastAPI from fastapi.responses import JSONResponse app = FastAPI () @app . post ( "/cookie/" ) def create_cookie (): content = { "message" : "Come to the dark side, we have cookies" } response = JSONResponse ( content = content ) response . set_co ...
https://man.mtool.work/fastapi/0.115/advanced/response-cookies/
バックグラウンドタスク 8036
バックグラウンドタスク レスポンスを返した 後に 実行されるバックグラウンドタスクを定義できます。 これは、リクエスト後に処理を開始する必要があるが、クライアントがレスポンスを受け取る前に処理を終える必要のない操作に役立ちます。 これには、たとえ ... p = FastAPI () def write_notification ( email : str , message = "" ): with open ( "log.txt" , mode = "w" ) as email_file : content = f "notification for { email } : { message } " email_file . write ( content ) @app . post ( "/send-notification/ {email} ... p = FastAPI () def write_notification ( email : str , message = "" ): with open ( "log.txt" , mode = "w" ) as email_file : content = f "notification for { email } : { message } " email_file . write ( content ) @app . post ( "/send-notification/ {email} ... p = FastAPI () def write_notification ( email : str , message = "" ): with open ( "log.txt" , mode = "w" ) as email_file : content = f "notification for { email } : { message } " email_file . write ( content ) @app . post ( "/send-notification/ {email} ...
https://man.mtool.work/fastapi/0.115/tutorial/background-tasks/
PREV 1 2 3 NEXT