Django adds sample code for the ES1en. ico icon

  • 2020-12-07 04:05:51
  • OfStack

favicon, short for Favorites Icon, lets your browser's favorites display not only the titles, but also the ICONS that distinguish one site from another.

By default, when the browser visits a site, it also requests the URL "/ favicon.ico" from the server to get the site icon.

If it is not configured, Django will return a 404 error and the browser will not display the 404 error, 1 will not be noticed.

But if the server turns on logging, the error will be recorded 1 straight away, adding up to a pile of useless records.

There are two ways to add the favicon. ico icon

First of all, make a ico file, using PS or some online ico site can be used, I was in the following site generated, of course, you can also use other sites!

http://tools.ofstack.com/aideddesign/ico_img

Name the file "ES29en. ico" and place it under static/blog/img/ after downloading

Method 1. Add to ES36en. py:


from Django.views.generic.base import RedirectView

urlpatterns=[
  ...
  # favicon.cio
  url(r'^favicon\.ico$', RedirectView.as_view(url=r'static/blog/img/favicon.ico')),   
]

The request "/ favicon ico", point to static blog/img/favicon ico this file, redeploy one project can see the effect you want.

Method 2. Redirect on the page:


<head>
  <meta charset="UTF-8">
  
  {% load staticfiles %}
  
    ...
    <link rel="shortcut icon" href="{%static " rel="external nofollow" blog/img/favicon.ico" %}" />
    ...

</head>

Refresh 1, you can see the effect oh!!

Remember, 1 must put it in the global head tag to get the desired effect!!


Related articles: