1

Or rather, it's returning them as text, which is really odd. So I have this line of code in my javascript to test this that's

 $.get('/static/js/categories.json', function(response){ console.log(response); });

I can verify that the actual location of the resource exists because the status code is 200, and I see responseText with the contents in the Chrome console window. Now the issue is that...

When I run it from the dev server locally there's only responseText

When I run it on the actual site, in the console, it returns responseJSON and responseText.

Does anyone know why this is the case? Essentially, it's not returning a javascript object

So the actual server runs apache. Is it possible that for some reason the Django dev server is setting the MIME types of responses incorrectly?


Apparent fix

Well it seems like this was the same problem encountered in this question. It was fixed by adding

if DEBUG:
    import mimetypes
    mimetypes.add_type("application/json", ".json", True)

In settings.py, but that doesn't answer the bigger question of WHY the development server can't correctly set the MIME type for some types of content

Edit

In fact, a lot of the mimetypes seem off. For instance, on my apache server .pngs are transferred as image/png while on the dev server it's image/x-png

Community
  • 1
  • 1
Jared Joke
  • 1,226
  • 2
  • 18
  • 29
  • Does switching `DEBUG` flag make any difference? – alecxe Mar 19 '14 at 01:03
  • It's current set to True. Setting it to False doesn't seem to fix the problem (it doesn't seem to allow me to run it without Debug=True) – Jared Joke Mar 19 '14 at 01:04
  • Could you check what is the `Content-Type` of the response locally and on the actual site? – alecxe Mar 19 '14 at 01:06
  • On the local site it's an "application/octet-stream" while on the site it's a "application/json". Weird... – Jared Joke Mar 19 '14 at 01:08
  • Could you show your `urls.py` part that configures serving static files? – alecxe Mar 19 '14 at 01:16
  • Also, could you follow [this answer](http://stackoverflow.com/a/14412233/771848) and check what is the mimetype guessed by the `mimetype` module locally and on the server? – alecxe Mar 19 '14 at 01:18
  • @alecxe is on it. django uses the python mimetypes module to determine the type. And I believe the mimetypes module itself uses different files in your environment to do the mapping, one of them being common apache files if available. So it's not really a problem with django dev server not being able to set the mimetype correctly, it's basically using what your dev environment provides. – toad013 Mar 19 '14 at 03:04
  • @toad013 thanks, this is what I was thinking about too. – alecxe Mar 19 '14 at 03:18

0 Answers0