Skip to content

Instantly share code, notes, and snippets.

@iepathos
Last active October 4, 2022 17:06
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save iepathos/5350503 to your computer and use it in GitHub Desktop.
Save iepathos/5350503 to your computer and use it in GitHub Desktop.
Fix for Google Chrome favicon loading in Django. You may have noticed that Chrome has issues loading the appropriate favicon on Django if you have it in a different path other than just '/favicon.ico'. Firefox follows the template icon links no problem, but Chrome needs a little more help. I fixed this issue by adding this quick line to the urls…
#urls.py
from django.conf import settings
urlpatterns = patterns('',
url(r'^favicon.ico/$', lambda x: HttpResponseRedirect(settings.STATIC_URL+'ico/favicon.ico')), #google chrome favicon fix
)
# base.html
<link rel="shortcut icon" href="{{ STATIC_URL }}ico/favicon.ico">
@bcoover
Copy link

bcoover commented Aug 12, 2016

or just put this in your urls.py:
url(r'^favicon\.ico$', RedirectView.as_view(url='/static/favicon/favicon.ico')),

@RonaldChonillo
Copy link

from django.views.generic.base import RedirectView
url(r'^favicon.ico$', RedirectView.as_view(url='/static/favicon/favicon.ico')),

Nice solution, thanks!

@shotgunner
Copy link

thanks it works 👍
I move HttpResponseRedirect(settings.STATIC_URL+'ico/favicon.ico') to separate view function for keep codes clean ;)

@n1254
Copy link

n1254 commented Apr 3, 2019

it works, thank you~~~

@johntovor
Copy link

This will work for those using Django 2.x and later...

from django.views.generic.base import RedirectView
path('favicon.ico/', RedirectView.as_view(url='/static/img/favicon/favicon.ico')),

NB:
Please put this in urls.py in your project folder; that is the folder which contains the "settings.py" file.
Also, take note of the location of the favicon.ico path. If your favicon.ico is located in "image" folder, then you have to provide that path like below:
path('favicon.ico/', RedirectView.as_view(url='/static/image/favicon.ico')),

@Arselon
Copy link

Arselon commented Dec 15, 2020

it works, thank you!!!

@LLigare
Copy link

LLigare commented Jan 24, 2021

on django 3.1.5, it works, thanks

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