开始使用Django应用程序,暂时只提供一些静态页面。一切似乎都在起作用,但我正在为我的CSS文件试图加载的一些网络字体资产获得500 HTTP响应。
我指的是我的CSS文件:
<link rel="stylesheet" type="text/css" href="{% static "css/styles.css" %}">
哪种方法很好,但在CSS中是指向webfonts的链接,它遵循FontSquirrel生成的标准格式。例如:
@font-face {
font-family: 'allerbold';
src: url("../fonts/aller_bd-webfont.eot");
src: url("../fonts/aller_bd-webfont.eot?#iefix") format("embedded-opentype"), url("../fonts/aller_bd-webfont.woff") format("woff"), url("../fonts/aller_bd-webfont.ttf") format("truetype"), url("../fonts/aller_bd-webfont.svg#allerbold") format("svg");
font-weight: normal;
font-style: normal; }
CSS正在引用正确的文件夹(&#39; css&#39;和#39;字体&#39;文件夹位于静态文件夹中的同一级别)但终端和浏览器控制台(Chrome)表示HTTP 500响应。
以下是其中一项的追溯:
Traceback (most recent call last):
File "C:\Server\Python34\lib\wsgiref\handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "C:\Server\Python34\lib\site-packages\django\contrib\staticfiles\handlers
.py", line 68, in __call__
return super(StaticFilesHandler, self).__call__(environ, start_response)
File "C:\Server\Python34\lib\site-packages\django\core\handlers\wsgi.py", line
206, in __call__
response = self.get_response(request)
File "C:\Server\Python34\lib\site-packages\django\contrib\staticfiles\handlers
.py", line 58, in get_response
return self.serve(request)
File "C:\Server\Python34\lib\site-packages\django\contrib\staticfiles\handlers
.py", line 51, in serve
return serve(request, self.file_path(request.path), insecure=True)
File "C:\Server\Python34\lib\site-packages\django\contrib\staticfiles\views.py
", line 41, in serve
return static.serve(request, path, document_root=document_root, **kwargs)
File "C:\Server\Python34\lib\site-packages\django\views\static.py", line 65, i
n serve
response["Last-Modified"] = http_date(statobj.st_mtime)
File "C:\Server\Python34\lib\site-packages\django\utils\http.py", line 109, in
http_date
rfcdate = formatdate(epoch_seconds)
File "C:\Server\Python34\lib\email\utils.py", line 181, in formatdate
now = time.gmtime(timeval)
OSError: [Errno 22] Invalid argument
[25/Apr/2014 13:19:09] "GET /static/fonts/aller_bd-webfont.svg HTTP/1.1" 500 59
感谢您的帮助!
答案 0 :(得分:1)
派对有点晚了,但是像我这样的其他Google员工发现了这个:
尝试删除&#39; Procedures
&#39;。在我的情况下,webfont没有任何问题,但是浏览器出现了相同的原始策略问题。 (更多信息at MDN)。
简而言之:使用&#39; ../
&#39;浏览字体并不总是被视为相同的来源,因此删除它将解决问题。
答案 1 :(得分:0)
经过一些试验和错误后,问题出现在webfont文件本身。我注意到FontSquirrel没有生成一组webfonts工作,所以我尝试使用不同的工具(www.web-font-generator.com)转换其他工具,现在他们都装好了。 / p>
为了验证这个发现,我使用两个生成器工具转换了另一个测试字体,果然,FontSquirrel中的那个没有工作,而来自Web-Font-Generator的那个没有。
奇妙!