Thursday, March 31, 2011

Re: Serve a tracking pixel via Django

On Fri, Apr 1, 2011 at 8:09 AM, Adam Nelson <> wrote:
> We have one static file that needs to be served after business logic has run
> (i.e. log a view on a specific url based on a unique code).  We used to use
> serve() in production.  This has always been frowned upon but with Django
> 1.3, the errors are worse.

Errors or warnings? There's a big difference. Errors mean it isn't
working. Warnings mean it is working, but something is telling you to
pay attention to something.

> Can one return an image in any other way?

Sure. Write a view that returns the content. It's 3 lines of code (a
couple more if you count imports and whitespace). Added bonus -- it's
actually more efficient than serve(), because it doesn't impose a disk
access overhead every time it gets called.


def tracking_pixel(request):
return HttpResponse(TRANSPARENT_1_PIXEL_GIF, content_type='image/gif')

Russ Magee %-)

You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

No comments:

Post a Comment