Django Favicon with Amazon S3

I had a little trouble today trying to get a favicon for my django site. I found some solutions online, but they assumed that you were serving your media statically through your apache server. I’m serving all my static files through Amazon S3, so those techniques didn’t work for me. Here’s how I did it instead.

First, I copied my favicon.ico to my S3 bucket. It’s just a 16×16 png file that I renamed.

In my settings file I made sure the MEDIA_URL was set to my S3 URL.

Then I made sure these things were imported in my urls.py

from django.conf import settings
from django.views.generic.simple import redirect_to

Lastly, I added this rule to my urls.py

(r'^favicon.ico$', redirect_to, {'url':settings.MEDIA_URL+'favicon.ico'}),

That’s it!

This entry was posted in Technology and tagged , , . Bookmark the permalink.

One Response to Django Favicon with Amazon S3

Comments are closed.