如何在Django rest框架中处理favicon请求? [英] How to handle favicon request in Django rest framework?
本文介绍了如何在Django rest框架中处理favicon请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我来自Node.js,我有一个与Django REST API通信的nextjs前端.但是,每次我向Django API发出请求时,该应用都会发出一个附加请求:
I am coming from Node.js and I have a nextjs frontend that communicates with a Django REST API. However, each time I make a request to my Django API, the app makes an additional request:
获取/favicon.ico
我尝试在 urls.py
favicon_view = RedirectView.as_view(url='/static/images/favicon.ico', permanent=True)
url(r'^favicon$',favicon_view)
但这是行不通的.
推荐答案
如果您在settings.py中设置了静态根目录,则您不会看到favicon的视图,您会转到前端并使用load static tag
you dont a view for favicon if you setup your static root in settings.py you go to your frontend and use load static tag
{% load static %}
,并在收藏夹链接中将其链接
and in favicon link you link it
<link rel="icon" href="{% static 'images/favicon.png' %}" sizes="16x16" type="image/png">
之后,您运行python manage.py collectstatic
after that you run python manage.py collectstatic
这篇关于如何在Django rest框架中处理favicon请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文