Currently, I am making a call to an API that sends back a zip file. When using request
:
res = requests.get('http://url/to/api, headers={auth: 'token', Accept: 'application/octet-stream'}
I am able to get the binary response content using res.content
:
Example:
b'PKx05x06...
Then I return the binary response from my view to my template:
return render(request, 'example.html', {'zipfile': res.content}
At my example.html
, I tried to create a button to download the zip file using:
<a href="data:application/zip, {{ zipfile }}" download>Download</a>
However, I got back a corrupted zip file.
I'm quite new to Django, any help here is appreciated, thanks!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…