Django - VIew 没有 return HttpResponse 对象,即使 HttpResponse returns
Django - VIew didn't return an HttpResponse Object even though HttpResponse returns
我得到的错误:
视图 report.views.csv_gen_universal 没有 return HttpResponse 对象。
def csv_gen_universal(req):
if req.POST['csvinputid']:
# Create the HttpResponse object with the appropriate CSV header.
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] ='attachment;filename="M_Wall_report.csv"'
writer = csv.writer(response)
content = str(req.POST['csvinputid']).split("^~^")
for m in content :
p = m.split("*~*")
writer.writerow(p)
return response
else:
HttpResponse("Wrong Place")
您忘记在 else 语句中添加 return
。你的代码应该是
def csv_gen_universal(req):
if req.POST['csvinputid']:
# Create the HttpResponse object with the appropriate CSV header.
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] ='attachment;filename="M_Wall_report.csv"'
writer = csv.writer(response)
content = str(req.POST['csvinputid']).split("^~^")
for m in content :
p = m.split("*~*")
writer.writerow(p)
return response
else:
return HttpResponse("Wrong Place")
我得到的错误:
视图 report.views.csv_gen_universal 没有 return HttpResponse 对象。
def csv_gen_universal(req):
if req.POST['csvinputid']:
# Create the HttpResponse object with the appropriate CSV header.
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] ='attachment;filename="M_Wall_report.csv"'
writer = csv.writer(response)
content = str(req.POST['csvinputid']).split("^~^")
for m in content :
p = m.split("*~*")
writer.writerow(p)
return response
else:
HttpResponse("Wrong Place")
您忘记在 else 语句中添加 return
。你的代码应该是
def csv_gen_universal(req):
if req.POST['csvinputid']:
# Create the HttpResponse object with the appropriate CSV header.
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] ='attachment;filename="M_Wall_report.csv"'
writer = csv.writer(response)
content = str(req.POST['csvinputid']).split("^~^")
for m in content :
p = m.split("*~*")
writer.writerow(p)
return response
else:
return HttpResponse("Wrong Place")