views.py
The download function using an API to convert a page to pdf using the URL. The pdf is saved in the project folder but i want it to be downloaded using HttpResponse
and if possible not saved in the folder but a variable instance in code pdf=file.write(response.content)
.
def downloadpdf(request, feedback_id):
apiKey = '*****************'
resume = Personal_Details.objects.get(feedback_id=feedback_id)
response = requests.post(
'https://api.restpdf.io/v1/pdf',
headers = {
'X-API-KEY' : apiKey,
'content-type': 'application/json'
},
json = {
"output": "data",
"url": "https://github.com/chryzcode"
}
)
if response.status_code == 200:
with open(f'{resume.resume_name}.pdf', 'wb') as file:
file.write(response.content)
return redirect('Resume', feedback_id=feedback_id)
else:
print("There was an error converting the PDF")