Question

Getting started on a Django application and just serving up some static pages for now. Everything seems to be working but I am getting a 500 HTTP response for some of the web font assets that my CSS file is trying to load.

I am referring to my CSS file using:

<link rel="stylesheet" type="text/css" href="{% static "css/styles.css" %}">

Which works fine, but within the CSS are links to webfonts, which is following the standard format generated by FontSquirrel. For example:

@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; }

The CSS is referencing the correct folder (the 'css' and 'fonts' folders are on the same level in the static folder) but both terminal and the browser console (Chrome) are indicating a HTTP 500 response.

Here's the traceback for one of these:

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

Thanks for any help!

Was it helpful?

Solution 2

After some trial and error it appears that the problem is with the webfont files themselves. I noticed a set of webfonts that weren't generated from FontSquirrel worked, so I tried converting the others using a different tool (www.web-font-generator.com) and now they're all loading fine.

To verify this finding I converted another test font using both generator tools and, sure enough, the one from FontSquirrel didn't work and the ones from Web-Font-Generator did.

Bizarre!

OTHER TIPS

A bit late to the party, but for other Googlers like me who found this:

Try removing the '../'. In my case there were no problems with the webfont, but the browser had problems with the 'same origin policy' (more info at MDN). In short: browsing for the fonts with '../' isn't always considered the same origin, so removing it will fix the problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top