emptygif
Ngôn ngữ: Tiếng Việt

Tất cả ngôn ngữ và framework

Litestar Python

Đoạn mã Python cho Litestar, trả lời các yêu cầu tới /pixel.gif bằng GIF rỗng, được giải mã một lần khi khởi động.

Litestar Python

Cài đặt
pip install "litestar[standard]"
Tệp
app.py
Chạy
litestar --app app:app run --port 8080
import base64

from litestar import Litestar, get
from litestar.datastructures import CacheControlHeader

GIF = base64.b64decode("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")


@get(
    "/pixel.gif",
    media_type="image/gif",
    cache_control=CacheControlHeader(no_store=True),
    include_in_schema=False,
)
async def pixel() -> bytes:
    return GIF


app = Litestar([pixel])

Chúng tôi đã chạy đoạn mã này và so sánh các byte nó trả về.

Kiểm tra

curl -sI http://localhost:8080/pixel.gif

Trang chính thức: Litestar

Thêm với Python