- Sort Score
- Num 10 results
- Language All
Results 1 - 10 of 13 for CustomORJSONResponse (0.2 seconds)
-
docs_src/custom_response/tutorial009c_py310.py
from fastapi import FastAPI, Response app = FastAPI() class CustomORJSONResponse(Response): media_type = "application/json" def render(self, content: Any) -> bytes: assert orjson is not None, "orjson must be installed" return orjson.dumps(content, option=orjson.OPT_INDENT_2) @app.get("/", response_class=CustomORJSONResponse) async def main():
Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Thu Feb 12 13:19:43 GMT 2026 - 451 bytes - Click Count (0) -
docs/en/docs/advanced/custom-response.md
Let's say you want it to return indented and formatted JSON, so you want to use the orjson option `orjson.OPT_INDENT_2`. You could create a `CustomORJSONResponse`. The main thing you have to do is create a `Response.render(content)` method that returns the content as `bytes`: {* ../../docs_src/custom_response/tutorial009c_py310.py hl[9:14,17] *} Now instead of returning:
Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Thu Mar 05 18:13:19 GMT 2026 - 11K bytes - Click Count (0) -
docs/zh-hant/docs/advanced/custom-response.md
你可以建立自己的自訂回應類別,繼承自 `Response` 並加以使用。 例如,假設你要使用 [`orjson`](https://github.com/ijl/orjson) 並套用一些設定。 假設你想回傳縮排且格式化的 JSON,因此要使用 orjson 選項 `orjson.OPT_INDENT_2`。 你可以建立 `CustomORJSONResponse`。你主要需要做的是建立一個 `Response.render(content)` 方法,將內容以 `bytes` 回傳: {* ../../docs_src/custom_response/tutorial009c_py310.py hl[9:14,17] *} 現在,不再是回傳: ```json {"message": "Hello World"} ```
Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Fri Mar 20 17:05:38 GMT 2026 - 10.3K bytes - Click Count (0) -
docs/fr/docs/advanced/custom-response.md
Disons que vous voulez renvoyer du JSON indenté et formaté, donc vous voulez utiliser l'option orjson `orjson.OPT_INDENT_2`. Vous pourriez créer une `CustomORJSONResponse`. L'essentiel est de créer une méthode `Response.render(content)` qui renvoie le contenu en `bytes` : {* ../../docs_src/custom_response/tutorial009c_py310.py hl[9:14,17] *} Maintenant, au lieu de renvoyer :
Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Thu Mar 19 18:37:13 GMT 2026 - 12.3K bytes - Click Count (0) -
docs/tr/docs/advanced/custom-response.md
Diyelim ki girintili ve biçimlendirilmiş JSON döndürmek istiyorsunuz; bunun için orjson seçeneği `orjson.OPT_INDENT_2`’yi kullanmak istiyorsunuz. Bir `CustomORJSONResponse` oluşturabilirsiniz. Burada yapmanız gereken temel şey, content’i `bytes` olarak döndüren bir `Response.render(content)` metodu yazmaktır: {* ../../docs_src/custom_response/tutorial009c_py310.py hl[9:14,17] *}
Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Fri Mar 20 07:53:17 GMT 2026 - 11.9K bytes - Click Count (0) -
docs/de/docs/advanced/custom-response.md
Sie möchten etwa, dass Ihre Response eingerücktes und formatiertes JSON zurückgibt. Dafür möchten Sie die orjson-Option `orjson.OPT_INDENT_2` verwenden. Sie könnten eine `CustomORJSONResponse` erstellen. Das Wichtigste, was Sie tun müssen, ist, eine `Response.render(content)`-Methode zu erstellen, die den Inhalt als `bytes` zurückgibt: {* ../../docs_src/custom_response/tutorial009c_py310.py hl[9:14,17] *}
Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Thu Mar 19 17:58:09 GMT 2026 - 12.5K bytes - Click Count (0) -
docs/es/docs/advanced/custom-response.md
Digamos que quieres que devuelva JSON con sangría y formato, por lo que quieres usar la opción de orjson `orjson.OPT_INDENT_2`. Podrías crear un `CustomORJSONResponse`. Lo principal que tienes que hacer es crear un método `Response.render(content)` que devuelva el contenido como `bytes`: {* ../../docs_src/custom_response/tutorial009c_py310.py hl[9:14,17] *}
Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Thu Mar 19 18:15:55 GMT 2026 - 11.6K bytes - Click Count (0) -
docs/zh/docs/advanced/custom-response.md
你可以创建你自己的自定义响应类,继承自 `Response` 并使用它。 例如,假设你想用一些设置来使用 [`orjson`](https://github.com/ijl/orjson)。 假设你想让它返回带缩进、格式化的 JSON,因此你想使用 orjson 选项 `orjson.OPT_INDENT_2`。 你可以创建一个 `CustomORJSONResponse`。你需要做的主要事情是实现一个 `Response.render(content)` 方法,并返回 `bytes`: {* ../../docs_src/custom_response/tutorial009c_py310.py hl[9:14,17] *} 现在,不再是返回: ```json {"message": "Hello World"} ```
Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Fri Mar 20 17:06:37 GMT 2026 - 10.4K bytes - Click Count (0) -
docs/ko/docs/advanced/custom-response.md
`Response`를 상속받아 사용자 정의 응답 클래스를 생성하고 사용할 수 있습니다. 예를 들어, [`orjson`](https://github.com/ijl/orjson)을 일부 설정과 함께 사용하고 싶다고 가정해봅시다. 들여쓰기 및 포맷된 JSON을 반환하고 싶다면, orjson 옵션 `orjson.OPT_INDENT_2`를 사용할 수 있습니다. `CustomORJSONResponse`를 생성할 수 있습니다. 여기서 핵심은 `Response.render(content)` 메서드를 생성하여 내용을 `bytes`로 반환하는 것입니다: {* ../../docs_src/custom_response/tutorial009c_py310.py hl[9:14,17] *} 이제 다음 대신: ```json {"message": "Hello World"}
Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Fri Mar 20 14:06:26 GMT 2026 - 12.4K bytes - Click Count (0) -
docs/ru/docs/advanced/custom-response.md
Скажем, вы хотите, чтобы возвращался отформатированный JSON с отступами, то есть хотите использовать опцию orjson `orjson.OPT_INDENT_2`. Вы могли бы создать `CustomORJSONResponse`. Главное, что вам нужно сделать — реализовать метод `Response.render(content)`, который возвращает содержимое как `bytes`: {* ../../docs_src/custom_response/tutorial009c_py310.py hl[9:14,17] *}
Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Thu Mar 19 17:56:20 GMT 2026 - 17.6K bytes - Click Count (0)