1

Hello I have a Django website with jquery for ajax calls.

The site is making several AJAX calls and the ones that are failing 500 ERROR from Django come with a Response header text/plain, if I rewrite the buggy url in the browser I see there is no text/plain response but text/html. Why? (I see accept header is different from ajax call */* and from the standard browser call text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8)

I need to get always text/html since if some of my ajax calls fails, I would like to save the answer (again with AJAX) in the server and be able to analyze it later (with full details, not just the plain/text which is reduced about debugging information).

I have tried adding accept:"text/html" and contenttype:"text" to the ajax call with no result.

Thanks,

1
  • might be worth adding some code - maybe the jquery ajax call the the django view it's calling.
    – Aidan Ewen
    Aug 20, 2012 at 10:37

2 Answers 2

0

Have a look here: https://docs.djangoproject.com/en/dev/howto/error-reporting/

When you run on the production server (with DEBUG = False) Django is supposed to send you an email with the details of the error to all the emails that you have included in the ADMIN variable

You can set the ADMIN variable like that

ADMINS = (
     ('jeff', '[email protected]'),
)

You don't need to try to log the error from the browser side. Instead you just have to fail nicely

1
  • Yes, I checked it out, but this emails are exactly the same output than text/plain (instad text/html). Actually the difference between this 2 is that texT/plain doesn't have debug information and text/html has plenty of information, so I can print it back to the browser from an admin panel and see exactly the error that the user was getting and be able to use debugging information given by django (debugging information not available in text/plain answer) Sep 26, 2012 at 20:23
0

When you're in development, just load the AJAX URL directly in the browser. You'll see the full stack trace like normal. Work on it until you get a real response (JSON, etc.), then go back to testing it within the scope of the rest of your code.

1
  • 1
    This is not really helpfull, a good solution should be unattended, the bug happens because of several random variables...difficult to reproduce. Most of this variables are user dependent. So I relaunch the question, how to make Django to answer to error pages with text/html when you POST from AJAX. :-) Sep 26, 2012 at 20:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.