0

Suppose i have this code

if form.is_valid(): 
   form.save()

Now suppose my form is valid i have exception that foregin key value is linked to more than one column so it will raise exception

Now i want to know is there any way to grab that exception value and pass to jquery via AJAX

Because form is valid so it comes inside the loop but its not able to go after form.save

So how can i program that if exception occurs it get passed to jquery like

if exception
   return HttpResponse(exception)

I get this exception

MultipleObjectsReturned at /manage/Source/create/ get() returned more than one Account -- it returned 3! Lookup parameters were {'account_number': u'121121'}

What type of exception it is

2
  • Really? Commented Jul 8, 2011 at 8:58
  • But i don't know what type of exception is there , can i catch all type of exceptions and put value in variable Commented Jul 8, 2011 at 9:10

1 Answer 1

1

MultipleObjectsReturned is the exception.

try:
    #do something
except MultipleObjectsReturned:
    return HttpResponse('MultipleObjectsReturned')

I wouldn't recommend using a bare try/except to catch all exceptions, as you won't know exactly what's wrong.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.