Django favicon.ico in development?

The easiest way would be to just put it in your static directory with your other static media, then specify its location in your html:

<link rel="shortcut icon" type="image/png" href="{% static 'images/favicon.ico' %}"/>

My old answer was:

You can set up an entry in your urls.py and just check if debug is true. This would keep it from being served in production. I think you can just do similar to static media.

if settings.DEBUG:
    urlpatterns += patterns('',
        (r'^favicon.ico$', 'django.views.static.serve', {'document_root': '/path/to/favicon'}),
    )

You also could just serve the favicon from your view.:

from django.http import HttpResponse

def my_image(request):
    image_data = open("/home/moneyman/public_html/media/img/favicon.ico", "rb").read()
    return HttpResponse(image_data, content_type="image/png")

This worked for me:

from django.conf.urls.static import static

...

if settings.DEBUG:
    urlpatterns += static(r'/favicon.ico', document_root='static/favicon.ico')

Tags:

Favicon

Django