Question: I'm using django to do a pixel tracker on an email

Is it easy to return an actual image from a django view (and how would this be done?) or is it easier to just return a redirect to the url where the actual image lives?

Answer: 
Django has a [static file](https://docs.djangoproject.com/en/dev/howto/static-files/) helper that could be used to serve up the image, but it is not recommended because of performance. I believe that having a view that does the bookkeeping to track the pixel, then redirect to a url that [serves the actual image via the webserver](https://docs.djangoproject.com/en/dev/howto/static-files/#serving-static-files-from-a-dedicated-server) is going to give you the best performance.
**Python2.x:**

```
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')

```

**Python3.x:**

```
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')

```

**Source:** <https://gist.github.com/simonw/10235798>