コンテンツにスキップ
per page, with , order by , clip by
Results of 1 - 6 of about 6 for HTMLResponse (0.002 sec.)
カスタムレスポンス - HTML、ストリーム、ファイル、その他のレスポンス 11077
カスタムレスポンス - HTML、ストリーム、ファイル、その他のレスポンス デフォルトでは、 FastAPI は JSONResponse を使ってレスポンスを返します。 レスポンスを直接返す で見たように、 Response を直接返すことでこの挙動をオーバーライドできます。 しか ... esponse は、現在はFastAPIのみで利用可能で、Starletteでは利用できません。 HTMLレスポンス FastAPI からHTMLを直接返す場合は、 HTMLResponse を使います。 HTMLResponse をインポートする。 path operation のパラメータ content_type に HTMLResponse を渡す。 Python 3.8+ ... from fastapi import FastAPI from fastapi.responses import HTMLResponse app = FastAPI () @app . get ( "/items/" , response_class = HTMLResponse ) async def read_items (): return """ <html> <head ... で見たように、レスポンスを直接返すことで、 path operation の中でレスポンスをオーバーライドできます。 上記と同じ例において、 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 10876
WebSocket FastAPI で WebSocket が使用できます。 WebSockets のインストール まず WebSockets のインストールが必要です。 $ pip install websockets ---> 100% WebSocket クライアント 本番環境 本番環境では、React、Vue.js、Angularなどの最新のフレーム ... 当て、実用的な例を示す最も簡単な方法です。 Python 3.8+ from fastapi import FastAPI , WebSocket from fastapi.responses import HTMLResponse app = FastAPI () html = """ <!DOCTYPE html> <html> <head> <title>Chat</title> </head> <body> <h1>WebSocket Chat</h1> <form ... value) input.value = '' event.preventDefault() } </script> </body> </html> """ @app . get ( "/" ) async def get (): return HTMLResponse ( html ) @app . websocket ( "/ws" ) async def websocket_endpoint ( websocket : WebSocket ): await websocket . accept () wh ... リケーションで、 websocket を作成します。 Python 3.8+ from fastapi import FastAPI , WebSocket from fastapi.responses import HTMLResponse app = FastAPI () html = """ <!DOCTYPE html> <html> <head> <title>Chat</title> </head> <body> <h1>WebSocket Chat</h1> <form ...
https://man.mtool.work/fastapi/0.115/advanced/websockets/
Request Files 10784
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 ... e : Python 3.9+ from typing import Annotated from fastapi import FastAPI , File , UploadFile from fastapi.responses import HTMLResponse app = FastAPI () @app . post ( "/files/" ) async def create_files ( files : Annotated [ list [ bytes ], File ()]): return ... ipart/form-data" method="post"> <input name="files" type="file" multiple> <input type="submit"> </form> </body> """ return HTMLResponse ( content = content ) ? Other versions and variants Python 3.8+ Python 3.9+ - non-Annotated Python 3.8+ - non-Annotated fr ... om typing import List from fastapi import FastAPI , File , UploadFile from fastapi.responses import HTMLResponse from typing_extensions import Annotated app = FastAPI () @app . post ( "/files/" ) async def create_files ( files : Annota ...
https://man.mtool.work/fastapi/0.115/tutorial/request-files/
Configure Swagger UI 8061
Configure Swagger UI Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . You can configure some extra Swagger UI parameters . To configure them, pass the swagger_ui_pa ... son from typing import Any , Dict , Optional from fastapi.encoders import jsonable_encoder from starlette.responses import HTMLResponse from typing_extensions import Annotated , Doc swagger_ui_default_parameters : Annotated [ Dict [ str , Any ], Doc ( """ De ... It defaults to [swagger_ui_default_parameters][fastapi.openapi.docs.swagger_ui_default_parameters]. """ ), ] = None , ) -> HTMLResponse : """ Generate and return the HTML that loads Swagger UI for the interactive API docs (normally served at `/docs`). You wo ... " ui.initOAuth( { json . dumps ( jsonable_encoder ( init_oauth )) } ) """ html += """ </script> </body> </html> """ return HTMLResponse ( html ) def get_redoc_html ( * , openapi_url : Annotated [ str , Doc ( """ The OpenAPI URL that ReDoc should load and use ...
https://man.mtool.work/fastapi/0.115/how-to/configure-swagger-ui/
Templates 7183
Templates Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . You can use any template engine you want with FastAPI . A common choice is Jinja2, the same one used by F ... to be used inside of the Jinja2 template. Python 3.8+ from fastapi import FastAPI , Request from fastapi.responses import HTMLResponse from fastapi.staticfiles import StaticFiles from fastapi.templating import Jinja2Templates app = FastAPI () app . mount ( ... name = "static" ) templates = Jinja2Templates ( directory = "templates" ) @app . get ( "/items/ {id} " , response_class = HTMLResponse ) async def read_item ( request : Request , id : str ): return templates . TemplateResponse ( request = request , name = " ... s, the request object was passed as part of the key-value pairs in the context for Jinja2. Tip By declaring response_class=HTMLResponse the docs UI will be able to know that the response will be HTML. Technical Details You could also use from starlette.templ ...
https://man.mtool.work/fastapi/0.115/advanced/templates/
Custom Response Classes - File, HTML, Redirect, Streaming, etc. 6799
Custom Response Classes - File, HTML, Redirect, Streaming, etc. There are several custom response classes you can use to create an instance and return them directly from your path operations . Read more about it in the FastAPI docs for Cust ... tream, File, others . You can import them directly from fastapi.responses : from fastapi.responses import ( FileResponse , HTMLResponse , JSONResponse , ORJSONResponse , PlainTextResponse , RedirectResponse , Response , StreamingResponse , UJSONResponse , ) ... ype - body - background - raw_headers - render - init_headers - headers - set_cookie - delete_cookie ::: fastapi.responses.HTMLResponse options: members: - charset - status_code - media_type - body - background - raw_headers - render - init_headers - headers ...
https://man.mtool.work/fastapi/0.115/reference/responses/
PREV 1 NEXT