我得到的错误:
视图report.views.csv_gen_universal未返回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")
答案 0 :(得分:3)
您忘了在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")