Django favicon.ico正在开发中?

Django favicon.ico正在开发中?,django,favicon,Django,Favicon,如何在开发中为favicon.ico服务?我可以在我的urlconf中添加一个路由,但我不想将该路由带入生产环境。在local_settings.py中是否有这样做的方法?好的,您可以创建自己的loader.py文件,加载您想要覆盖的设置。 加载此文件应如下所示: try: execfile(os.path.join(SETTINGS_DIR, 'loader.py')) except: pass 并添加到settings.py的末尾。 此设置不应提交到生产服务器,只应出现在开

如何在开发中为favicon.ico服务?我可以在我的urlconf中添加一个路由,但我不想将该路由带入生产环境。在local_settings.py中是否有这样做的方法?

好的,您可以创建自己的loader.py文件,加载您想要覆盖的设置。 加载此文件应如下所示:

try:
    execfile(os.path.join(SETTINGS_DIR, 'loader.py'))
except:
    pass
并添加到settings.py的末尾。
此设置不应提交到生产服务器,只应出现在开发计算机上。如果您使用的是git,请将loader.py添加到.gitignore中。

最简单的方法是将其与其他静态媒体一起放入静态目录,然后在html中指定其位置:

<link rel="shortcut icon" type="image/png" href="{% static 'images/favicon.ico' %}"/>
从你的观点来看,你也可以为法维康服务

from django.http import HttpResponse

def my_image(request):
    image_data = open("/home/moneyman/public_html/media/img/favicon.ico", "rb").read()
    return HttpResponse(image_data, content_type="image/png")
从:

似乎没有办法为单个静态文件提供服务,但至少这个helper函数是一个包装器,它只在DEBUG=True时起作用。

这对我来说很有效:

from django.conf.urls.static import static

...

if settings.DEBUG:
    urlpatterns += static(r'/favicon.ico', document_root='static/favicon.ico')

我已将其标记为正确,但仔细检查后,它实际上不起作用。django.views.static.serve将只服务于目录,而不是单个文件。
from django.conf.urls.static import static

urlpatterns = patterns("",
    # Your stuff goes here
) + static('/', document_root='static/')
from django.conf.urls.static import static

...

if settings.DEBUG:
    urlpatterns += static(r'/favicon.ico', document_root='static/favicon.ico')