django多重响应(附上pdf和更新模板)

时间:2016-02-19 22:44:11

标签: django csv response

我需要附加一个csv文件并使用view.py中的参数刷新网站,我有这个:

(上下文包含模板参数)

    if create_csv == 1:
    response_CSV = export_csv(request, pat_list, context, template)
    return response_CSV

...

  def export_csv(request, queryset, context, template):
    import csv
    from django.utils.encoding import smart_str
    response = HttpResponse(template.render(context, request))
    response['Content-Disposition'] = 'attachment; filename= filter.csv'
    writer = csv.writer(response, csv.excel)
    response.write(u'\ufeff'.encode('utf8'))
    writer.writerow([
        smart_str(u"Name"),
        smart_str(u"Age"),
    ])
    for obj in queryset:
        writer.writerow([
            smart_str(obj.Name),
            smart_str(obj.age),
        ])
    return response

此代码仅发送下载文件,但不使用内容参数刷新网站,我可以这样做吗?

0 个答案:

没有答案