emptygif
언어: 한국어

모든 언어 및 프레임워크

Pyramid Python

/pixel.gif 요청에 빈 GIF로 응답하는 Pyramid용 Python 스니펫입니다. GIF는 시작할 때 한 번만 디코딩합니다.

Pyramid Python

설치
pip install pyramid
파일
app.py
실행
python app.py
import base64
from wsgiref.simple_server import make_server

from pyramid.config import Configurator
from pyramid.response import Response

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


def pixel(request):
    return Response(body=GIF, content_type="image/gif", cache_control="no-store")


if __name__ == "__main__":
    with Configurator() as config:
        config.add_route("pixel", "/pixel.gif")
        config.add_view(pixel, route_name="pixel", request_method="GET")
        app = config.make_wsgi_app()
    make_server("0.0.0.0", 8080, app).serve_forever()

이 스니펫은 실행해 보고, 반환된 바이트를 비교했습니다.

확인

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

공식 사이트: Pyramid

Python의 다른 예제