I’ve tested this out thoroughly and I have no idea why it’s doing this, so I was wondering if someone could explain…
json.dumps() is throwing a 500 internal server error when I try to use a variable instead of a string.
For example:
error = 'Login Failed: Your username or password is incorrect.'
test = json.dumps({'form': error})
will return a 500 internal server error when attempting to return through jQuery.ajax
However,
test = json.dumps({'form': 'Login Failed: Your username or password is incorrect.'})
will not throw a 500 internal server error. I’ve tested this out thoroughly with single quotes, double quotes, different formatting, etc and it all points to json.dumps()
For some reason, this is only occurring when calling the view through jQuery.ajax
even if i don’t return json.dump() and return a normal json object it still throws a 500 error, which is why I’ve concluded that it’s json.dumps() and not the .ajax call **
Here’s an extra snippet of code where I’m using this: For unknown reasons.. this will throw an error while calling this particular page through jQuery.ajax()
Yes.. even though the variable ‘test’ is not being returned.
elif(password == 'testing_this'):
error = 'Login Failed: Your username or password is incorrect.'
errors = True
test = json.dumps({'form': error})
#print test
date = datetime.date.today()
if(errors == True):
return HttpResponse(json.dumps({'form': 'error message here'}), mimetype='application/json')
else:
return HttpResponse(json.dumps({'result': True}), mimetype='application/json')
Turning DEBUG on in settings, and going through traceback may be useful.
Just of the wall, i may assume that before this check (if(errors == True):) You may forgot to initialize errors with initial value so it throws NameError… But it’s just an assumption.
UPD: Sorry ajax part slipped my mind – +1 to waitinforatrain’s comment