Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'dict' object has no attribute 'status_code' error in django project

Tags:

django

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
like image 742
user3153069 Avatar asked Nov 30 '22 19:11

user3153069


2 Answers

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.

like image 156
toudi Avatar answered Dec 04 '22 04:12

toudi


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 {
            ...
        }
    }
});
like image 27
WesternGun Avatar answered Dec 04 '22 05:12

WesternGun