Download pdf file Django

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 =
    headers = {
        'X-API-KEY'   : apiKey,
        'content-type': 'application/json'
    json = {
        "output": "data",
        "url": ""
    if response.status_code == 200:
        with open(f'{resume.resume_name}.pdf', 'wb') as file:
            return redirect('Resume', feedback_id=feedback_id)

        print("There was an error converting the PDF")

enter image description here

 response = HttpResponse(pdf, content_type='application/pdf')
 response['Content-Disposition'] = 'attachment; filename="' + filename + '"'

you can return file like this

Back to Top