Redirection after downloading excel file from views.py

I’m asking users to upload file to be read and processed via template and as they click submit processing starts and at frontend I have onclick function that triggers when submit button is clicked and it starts a spinner to show user that view is processing file and file downloads after processing using content-disposition but i can’t make spinner stop as main function working on request is returning file and if I use another return then somehow file doesn’t download as http request for redirect supersedes file download because views work on backend without checking if frontend has processed file download on client side or not.

def downloadFile():
    # DOWNLOADING THE FILE TO LOCAL SYSTEM

    try:
        print('Try downloading block')


        with pd.ExcelWriter('NEW-DOWNLOAD.xlsx', engine='openpyxl') as excel_file_path:
            # Write dataframes to sheets
            dataframes = {
                'TRIP-SUMMARY': df1,
                'DEPARTURE-CHART': df2
            }
            for sheet_name, df in dataframes.items():
                df.to_excel(excel_file_path, sheet_name=sheet_name, index=True)

        # Read the entire file as bytes
        with open('NEW-DOWNLOAD.xlsx', 'rb') as f:
            file_data = f.read()
        # Create an HttpResponse with the Excel file as attachment
        response = HttpResponse(file_data, content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
        response['Content-Disposition'] = 'attachment; filename="NEW-DOWNLOAD.xlsx"'

        return response
        
    except Exception as e:
        print('Error:', e)
        return None
downloaded_response = downloadFile()
  
if downloaded_response:
    try:
        print('downloaded_response',downloaded_response)
        return downloaded_response
    except:
        print('EXCEPT')

This works but spinner doesn’t stop and if I redirect using finally statement then download doesn’t takes place I can only see HttpResponse by using print but download never happens, is there any workaround.