Skip to content

Instantly share code, notes, and snippets.

@zhasm
Last active December 15, 2015 04:59
Show Gist options
  • Save zhasm/5206108 to your computer and use it in GitHub Desktop.
Save zhasm/5206108 to your computer and use it in GitHub Desktop.
font awesome 在firefox 下不能正常显示。搜索到基于 apache .htaccess 的解决方案(http://is.gd/3UrgIp),于是写出对应的django 解决方案。
#urls.py
url(r'^media/font/(?P<font>.*(?:eot|ttf|oft|woff))$', views.font, name='font'),
#views
import os
from django.conf import settings
def font(request, font):
font_fn = os.path.abspath(os.path.join(settings.MEDIA_ROOT, 'font/%s' % font))
if os.path.exists(font_fn):
return HttpResponse(open(font_fn).read(), 'font/otf')
else:
return HttpResponse('', 'font/otf')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment