From my server, I'm reading my pkpass file and converting it to base64. I want to make this file downloadable on my template. Here's what I'm doing.
Server/Python (Django)
passfile_bytes = passfile.read()
passfile_base64 = base64.b64encode(passfile) # This is sent to template
Template/HTML
<a href="data:application/vnd.apple.pkpass;base64,{{ passfile_base64 }}" download="file.pkpass">
Download
</a>
I know I'm messing up the href
here because the download fails. How do I actually make this ready for download when the link is clicked?
CodePudding user response:
base64.b64encode
returns a bytes
object, you need to convert it to a string:
passfile_base64 = base64.b64encode(passfile).decode('ascii')