我用 django 编写了一个代码,用户可以在其中搜索数据库表中的单词。我的问题是当我打印返回的结果时,它们包含引号。我怎样才能省略它们?
def My_data_filed(request):
form = data_filed_Form(request.POST or None)
data = None
download_form = None
if request.method == 'POST':
if form.is_valid():
data_g = form.cleaned_data.get('g')
data = list(data_filed.objects.filter(g__contains=data_g).values())
print(data_filed.objects.all().values())
download_form = data_filed_DownloadForm(initial={
'g': data_g,
})
return render(request, 'search_report.html',
{
'form': form,
'data': data,
'download_form': download_form
})
这段代码的输出是这样的:
'Creator': 'Davide'
但我只想拥有:
Davide
我的努力有什么问题?
我将获取的结果写入 csv 文件的代码:(因为从评论中我了解到这部分也是相关的)
def resultDownload(request):
try:
assert request.method == 'POST'
form = data_DownloadForm(request.POST)
assert form.is_valid()
data_g = form.cleaned_data.get('g')
data = list(data_filed.objects.filter(data__contains=g).values_list())
except AssertionError:
error = 'Your request has some problems.'
data = error
attachment = 'SearchedReport.csv'
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment;filename="{}"'.format(attachment)
response.write(data)
return response