Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serving favicon.ico with Django. Why does settings.MEDIA_URL with django.views.generic.simple.redirect_to only work on dev environment?

Tags:

I found this solution for serving favicon.ico with django.

(r'^favicon\.ico$',   'django.views.generic.simple.redirect_to',   {'url': settings.MEDIA_URL+'images/favicon.ico'}), 

I do not understand why it only works for the development server. Going to /favicon.ico works on dev, doesn't with debug=False. It should redirect to /media/images/favicon.ico (served by apache), which does work if you access it directly.

Any ideas?

like image 565
Clash Avatar asked Aug 11 '10 17:08

Clash


People also ask

How to fix favicon error in Django?

If you are still getting favicon errors and the Django favicon is not working, you need to make sure the favicon file is spelled correctly and saved in the right folder. The example above uses the path static > img, meaning the favicon is located in the project folder > static > img folder.

Where to put favicon in Django project?

Move this file into your project within the static directory so it should be static/favicon. ico . For the final step, update our template so that we include load static at the top and then add an href for our favicon.


2 Answers

I'd recommend against serving the favicon with django unless you absolutely have to. Instead, putting a setting in your web server config that adds an alias pointing to the favicon.

For example, in apache:

Alias /favicon.ico /path/to/media_url/images/favicon.ico 
like image 122
Jordan Reiter Avatar answered Oct 12 '22 22:10

Jordan Reiter


This is not direct answer to you question, but you can use this for favicon:

<link rel="shortcut icon" href="{{ STATIC_URL }}img/favicon.ico" /> 
like image 23
Sergey Lyapustin Avatar answered Oct 12 '22 21:10

Sergey Lyapustin