Django Python
Django માટે Python સ્નિપેટ, જે /pixel.gif પરની રિક્વેસ્ટનો જવાબ empty GIF થી આપે છે. GIF સ્ટાર્ટઅપ વખતે એક જ વાર ડિકોડ થાય છે.
Django Python
# pixels/views.py
import base64
from django.http import HttpResponse
from django.views.decorators.http import require_GET
GIF = base64.b64decode("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")
@require_GET
def pixel(request):
return HttpResponse(GIF, content_type="image/gif", headers={"Cache-Control": "no-store"})
# pixels/urls.py (include("pixels.urls") from the project's urls.py)
from django.urls import path
from . import views
urlpatterns = [
# Django URL patterns are written without the leading slash.
path("/pixel.gif".lstrip("/"), views.pixel, name="pixel"),
]
અમે આ સ્નિપેટ ચલાવ્યો અને તેણે પરત કરેલા બાઇટની સરખામણી કરી.
ચકાસો
curl -sI http://localhost:8080/pixel.gif
Python માં વધુ
- AWS Lambda (Python)
- Google Cloud Run functions (Python)
- FastAPI
- Litestar
- Starlette
- Flask
- aiohttp
- Sanic
- Quart
- Falcon
- Robyn
- BlackSheep
- Tornado
- Bottle
- Pyramid
- Microdot (CPython and MicroPython)
- Raw ASGI (Uvicorn, Granian, Hypercorn)
- Raw WSGI (Gunicorn, uWSGI, mod_wsgi)
- Python standard library (http.server)
- Python one-liner