5

I am getting this error in my django project, how can i resolve it.

Traceback Switch to copy-and-paste view

/home/vishakha/webapps/django/local/lib/python2.7/site-packages/django/core/handlers/base.py in get_response
            response = self.apply_response_fixes(request, response) ...
▶ Local vars
/home/vishakha/webapps/django/local/lib/python2.7/site-packages/django/core/handlers/base.py in apply_response_fixes
            response = func(request, response) ...
▶ Local vars
/home/vishakha/webapps/django/local/lib/python2.7/site-packages/django/http/utils.py in conditional_content_removal
    if 100 <= response.status_code < 200 or response.status_code in (204, 304): ...
▶ Local vars
2
  • Test for 'status_code' key existence before accessing it or catch and handle the error yourself. Commented May 11, 2014 at 1:54
  • You need to put in more effort to explain your question! FWIW, naming a view function test causes this error in my app. I have no idea why... I can't find any name collisions although that would be my first guess. (I have no idea if you did that, but it might help!) Commented Sep 8, 2014 at 2:15

3 Answers 3

15

Looks like you are not returning a instance of HttpResponse from your view. could you paste a code snippet? also, please try to unfold a highlighted exception (it's coloured with a dark grey background) and see what's the value of 'response' variable.

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

Comments

6

Yes, @toudi is right. I am in such situation and now I do:

from django.http.response import JsonResponse

return JsonResponse({'success':False, 'errorMsg':errorMsg})

When you process the json part in jQuery, do:

$.ajax({
    ...
    dataType: 'json',
    success: function(returned, status, xhr) {
        var result = returned['success']; // this will be translated into 'true' in JS, not 'True' as string
        if (result) { 
            ...
        else {
            ...
        }
    }
});

Comments

0

You should show your view; I suspect that you are simply returning the dict from your view, whereas you should be returning an HttpResponse.

if view returns serializable dict, you may have to convert it into JsonResponse

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.