使用 Django 提供 favicon.ico。为什么带有 django.views.generic.simple.redirect_to 的 settings.MEDIA_URL 仅适用于开发环境?
我找到了使用 django 提供 favicon.ico 的解决方案。
(r'^favicon\.ico$',
'django.views.generic.simple.redirect_to',
{'url': settings.MEDIA_URL+'images/favicon.ico'}),
我不明白为什么它只适用于开发服务器。 转到 /favicon.ico 在 dev 上有效,但在 debug=False
上无效。 它应该重定向到 /media/images/favicon.ico (由 apache 提供),如果您直接访问它,它就可以工作。
有什么想法吗?
I found this solution for serving favicon.ico with django.
(r'^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?
,
'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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我建议不要使用 django 提供 favicon,除非绝对必要。相反,您可以在 Web 服务器配置中添加一个设置,添加指向该图标的别名。
例如,在阿帕奇中:
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:
这不是对您问题的直接回答,但您可以将其用于网站图标:
This is not direct answer to you question, but you can use this for favicon:
redirect_to 已在 Django 1.5 中已弃用。您可以使用基于类的 RedirectView
redirect_to has been deprecated in Django 1.5. You can use the class based RedirectView