50
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.
39
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')),
]
- [Django]-Django models ForeignKey on_delete attribute: full meaning?
- [Django]-TemplateDoesNotExist β Django Error
- [Django]-In a Django form, how do I make a field readonly (or disabled) so that it cannot be edited?
12
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.
- [Django]-Import data from excel spreadsheet to django model
- [Django]-Foreign key from one app into another in Django
- [Django]-Permission denied β nginx and uwsgi socket
7
-
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 oursettings.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!
- [Django]-Django 1.11 Annotating a Subquery Aggregate
- [Django]-Writing a __init__ function to be used in django model
- [Django]-Django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
6
Your browser is looking for a favicon that it can display in the Location Bar. Either give it one, or ignore the warning.
- [Django]-Is there a function for generating settings.SECRET_KEY in django?
- [Django]-Celery discover tasks in files with other filenames
- [Django]-Composite primary key in django
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.
βββ
- [Django]-How to get the ID of a just created record in Django?
- [Django]-Django celery task: Newly created model DoesNotExist
- [Django]-Django content-type : how do I get an object?
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>
- [Django]-How to output Django queryset as JSON?
- [Django]-What's the difference between ContentType and MimeType?
- [Django]-How does the get_or_create function in Django return two values?
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),
...
]
- [Django]-How can I test https connections with Django as easily as I can non-https connections using 'runserver'?
- [Django]-OSError β Errno 13 Permission denied
- [Django]-Django include template from another app
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>
- [Django]-Django: How to build a custom form widget?
- [Django]-History of Django's popularity
- [Django]-Embedding JSON objects in script tags