Skip to content

Instantly share code, notes, and snippets.

@simonw
Created April 9, 2014 07:27
Show Gist options
  • Save simonw/10235798 to your computer and use it in GitHub Desktop.
Save simonw/10235798 to your computer and use it in GitHub Desktop.
Return a 1x1 pixel gif from Django (e.g. for a dynamic tracking pixel)
from django.http import HttpResponse
PIXEL_GIF_DATA = """
R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
""".strip().decode('base64')
def pixel_gif(request):
return HttpResponse(PIXEL_GIF_DATA, content_type='image/gif')
@bpsagar
Copy link

bpsagar commented Apr 5, 2018

For Python 3

import base64
from django.http import HttpResponse

PIXEL_GIF_DATA = base64.b64decode(
    b"R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7")

def pixel_gif(request):
    return HttpResponse(PIXEL_GIF_DATA, content_type='image/gif')

Thank you for this gist 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment