我在django项目中收到此错误,我该如何解决呢。
回溯切换到复制并粘贴视图
/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
答案 0 :(得分:12)
看起来您没有从视图中返回HttpResponse的实例。你能粘贴代码片段吗?另外,请尝试展开一个突出显示的例外(它用深灰色背景着色),看看&#39;响应&#39;的价值是什么?变量
答案 1 :(得分:1)
是的,@ toudi是对的。我处于这种状况,现在我做了:
from django.http.response import JsonResponse
return JsonResponse({'success':False, 'errorMsg':errorMsg})
在jQuery中处理json部分时,请执行:
$.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 {
...
}
}
});
答案 2 :(得分:0)
您应该展示您的观点;我怀疑您只是从视图中返回字典,而应该返回HttpResponse。
如果视图返回可序列化的dict,则可能必须将其转换为JsonResponse