55

I'm new to Python and Django. I'm seeing this error message after I perform runserver, when trying to log in from my landing page,

$ python manage.py runserver
Running in development mode.
Running in development mode.
Running in development mode.
Running in development mode.
Validating models...

0 errors found
Django version 1.4b1, using settings 'platformsite.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[21/Feb/2012 02:33:26] "GET /accounts/home/ HTTP/1.1" 200 10698
WARNING 2012-02-21 02:33:27,204 base 41333 4353703936 Not Found: /favicon.ico
[21/Feb/2012 02:33:30] "POST /accounts/home/ HTTP/1.1" 200 11098
WARNING 2012-02-21 02:33:30,581 base 41333 4362117120 Not Found: /favicon.ico
[21/Feb/2012 02:33:35] "POST /accounts/home/ HTTP/1.1" 200 10975
WARNING 2012-02-21 02:33:36,333 base 41333 4370530304 Not Found: /favicon.ico
[21/Feb/2012 02:33:57] "POST /accounts/home/ HTTP/1.1" 200 10975
WARNING 2012-02-21 02:33:57,670 base 41333 4349497344 Not Found: /favicon.ico

I'm on Python 2.7, Django 1.4, and OS X 10.7 What is this warning about and how do I get rid of it?

Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
henghonglee
  • 1,732
  • 3
  • 20
  • 29
  • you can check this answer https://stackoverflow.com/questions/21938028/how-can-i-get-a-favicon-to-show-up-in-my-django-app/57042608#57042608 – Mustapha-Belkacim Apr 15 '21 at 09:34

9 Answers9

48

Most browsers look for the existence of an file called favicon.ico at the root path of your website domain, this controls the icon for the website you can see in your bookmarks folder or the address bar of your browser.

If you don't have one, then it's valid that it would return a Not Found error.

mauris
  • 42,982
  • 15
  • 99
  • 131
Russ Clarke
  • 17,511
  • 4
  • 41
  • 45
  • 1
    As Ignacio said; it's fine to ignore this; but if you're like to generate one then this site is helpful: http://www.favicon.co.uk/ – Russ Clarke Feb 21 '12 at 02:40
  • 1
    That site's a little out of date; favicons no longer need to be .ico files or very small images. – Ignacio Vazquez-Abrams Feb 21 '12 at 02:42
  • Fair enough! It's been a little while since I've needed one! Although, if you expect a certain amount of traffic to your new site then making it as small as possible is only doing a favour to your clients and customers, and a reduction in your own network traffic! Every little bit helps. – Russ Clarke Feb 21 '12 at 02:44
  • 9
    It's pretty clear what the cause is, but if you don't want a favicon how would you disable the warning? – eric Aug 10 '17 at 16:11
  • Hello, where is "root path of your website domain" exactly? I have put it next to the `config` folder, inside `templates` folder, inside `static` folder, but the Browser does not show the icon :( – Shayan Dec 15 '21 at 08:20
  • 2
    @Shayan root path of your website domain is whatever comes right immediately after your domain name. So, for a domain `example.com`, you can say `logo.png` is in the root path of the domain if its URL is `example.com/logo.png`. This root path should not be confused with Django's project root or template directory. – Sabya Jan 03 '22 at 05:57
38

When you deploy to something like Apache, you will have to alias your favicon in a config file. However, while running Django in development mode, the following works

urls.py:

from django.views.generic import RedirectView
from django.conf.urls import url

url_patterns=[
    ...

    url(r'^favicon\.ico$',RedirectView.as_view(url='/static/images/favicon.ico')),
]
cegprakash
  • 2,937
  • 33
  • 60
Sebastian
  • 1,623
  • 19
  • 23
11

Almost all Browsers usually look for the existence of a file called favicon.ico at the root path of the website domain, this controls the icon for the website that we can see in the tabs, bookmarks folder or the address bar of the browser.

When the browser searches for favicon.ico and does not find the same, then it is valid that it would return a Not Found error.

django.contrib.staticfiles.storage provides staticfiles_storage, which is an instance of your project’s configured static file storage. Storages have a URL method that “[r]eturns an absolute URL where the file’s contents can be accessed directly by a Web browser.”, which is exactly what the {% static %} tag uses.

So {% static 'favicon.ico' %} in a template is essentially equivalent to staticfiles_storage.url('favicon.ico') in Python. We can add <link rel="icon" href="{% static 'base/icons/favicon.ico' %}"> under <head> tag to the base.html of django.

When we get such error in other domains with error code 404, the link for favicon can be added under <head> section we can add <link> as follows:

<link rel="icon" href="static/projectname/favicon.ico">

or

<link rel="shortcut icon" type="image/x-icon" href="base/icons/favicon.png"/>

Do not forget to add the required location of the icon file favicon.ico, the issue will be resolved.

The favicon.ico could be the logo of the company or anything the website is based upon.

S Habeeb Ullah
  • 968
  • 10
  • 15
6
  • I was facing same problem favicon.ico not found.

  • I converted my image file to favicon.ico from https://favicon.io/favicon-converter/.

  • After downloading the zip file, then created new folder by name favicon and copy all the file inside zip or you can extract to favicon folder.

  • After that I simply copied the favicon folder and pasted inside the static folder.

  • I update this line of code in urls.py file, the folder in which our settings.py file exist.

     from django.urls import path
     from . import views
     from django.contrib.staticfiles.storage import staticfiles_storage
     from django.views.generic.base import RedirectView
    
     urlpatterns = [    
          path('favicon.ico', RedirectView.as_view(url=staticfiles_storage.url('favicon/favicon.ico')))
     ]
    
  • Probably my error get solved.

  • Hope this will help you!

Paolo
  • 20,112
  • 21
  • 72
  • 113
Sandip
  • 61
  • 1
  • 2
6

Your browser is looking for a favicon that it can display in the Location Bar. Either give it one, or ignore the warning.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
2

You can serve static files by sending the static_path setting as a keyword argument. We will serve those files from the /static/ URI (this is configurable with the static_url_prefix setting), and we will serve /favicon.ico and /robots.txt from the same directory. A custom subclass of StaticFileHandler can be specified with the static_handler_class setting. """

langiac
  • 317
  • 1
  • 3
  • 16
0

An easy way to do it is to create an alias in your apache conf file:

<VirtualHost *:443>
    ...
    Alias /favicon.ico /path/to/your/favicon.ico
    ...
</VirtualHost>
huseyin39
  • 1,393
  • 12
  • 18
0

I was building a web api and ran into this as well. As it was just a demo project, I threw a dummy response at the browser to make the error go away. In the main urls.py, I added my little fake view above it. Obviously, in production, you would just keep that icon in the static root, the location of which you set in the server config file.

from django.http import HttpResponse

def okay(request):
    return HttpResponse('pretend-binary-data-here', content_type='image/jpeg')

urlpatterns = [
    path('favicon.ico', okay),
    ...
] 
Ryan Dines
  • 979
  • 10
  • 18
0

If you just want to remove the warning without setting your own favicon, add <link rel="icon" ...> to <head></head> in base.html as shown below. *The answer explains <link rel="icon" ...> below and my answer explains how to set favicon for Django and my answer explains how to set favicon for Django Admin:

{# "base.html" #}

<head>
...
<link rel="icon" href="data:,"> {# Here #}
...
</head>
Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129