简体   繁体   中英

how to return an excel sheet and a string response using httpresponse Django Python

I am currently returning a response page as a string but I also want to pass it as an excel file. I am having trouble doing both.

This is my views.py file:

response = HttpResponse(htmlString)
response = HttpResponse(mimetype='application/vnd.ms-excel')
response['Content-Disposition'] = 'attachment; filename=example1.xls'
book.save(response)    

return response

This only gives me the excel file and not the HtmlString which is because I am reassigning response but I dont know how to include both paramaters.

THanks in advance!!

A HTTP response (as in the HTTP protocol, this is not limited to Django) will be treated by the browser either as a file, or displayed in the browser (html, plain text, etc). You cannot return a response with both.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM