0
点赞
收藏
分享

微信扫一扫

django显示favicon.ico

urls.py


urlpatterns = [

# ...

url(r'^favicon.ico$', MainApp_Views.favicon),

]





views.py



def favicon(request):

imgDir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

imgDir = os.path.join(imgDir, 'common_static')

imgDir = os.path.join(imgDir, 'images')

imgFilePath = os.path.join(imgDir, 'favicon.ico')

# return HttpResponse('favicon...' + imgFilePath)

image_data = open(imgFilePath, "rb").read()

return HttpResponse(image_data, content_type="image/png") # 注意旧版的资料使用mimetype,现在已经改为content_type

举报

相关推荐

0 条评论