2

I use jQuery(ajax) in django, and I want when happen error in django server i get server error instead "the server responded with a status of 500 (INTERNAL SERVER ERROR)"
In fact I want to get django error msg (for example "KeyError or model not found and etc." in ajax function

$.ajax({
    ...
success:function(json){
    ...
},
error:function(xhr,errmsg,err){

    // this here i want to show django error)
    alert(django error msg);
}
});

thanks.

Gertsen
  • 1,078
  • 20
  • 36
  • Possible duplicate of [Returning pure Django form errors in JSON](http://stackoverflow.com/questions/986406/returning-pure-django-form-errors-in-json) – Sheepy Jan 26 '16 at 07:49
  • but i dont use form.error happen in views when i try to create new instance of a model: 'ins = Comment.objects.create(...)' –  Jan 26 '16 at 08:03
  • where is your view and whole ajax code? That's important for displaying errors in the ajax call. – Yaaaaaaaaaaay Jan 26 '16 at 08:51
  • Why do you need this? It's generally a bad idea to leak the error details to front end. If think you need it for development - use a debugger and write unit tests instead. – Tomas Walch Jan 26 '16 at 10:22
  • thank you evryone.my problem is solved.i finaly forced to use try...except –  Jan 26 '16 at 19:11

0 Answers0