Q: Export to excel in django not working quite as i hoped it would I am a django beginner, Trying to export an excel writer to excel in a django front end app using the results of  function1 in function2 which contains the code to export/download the file but i can't seem to get it to work. It works when i include the export to excel code in function1 in my views.py (its a project with quite some sensitive data hence why i wont be sharing the actual code here). Each function has a button that run it to provide the required output but This doesnt work, i appreciate any help on this
def function1(request):
   #post method request with filters from the frontend

   #use filters to read in the data
    df = read_sql("query with filters")
 
   #created a writer
    output = BytesIO()
    writer = pd.ExcelWriter(output, engine='xlsxwriter')

   #called functions that send output to writer sheets, see example below
    check_for_duplicates(df,writer)
   #create context to render some sample output on the frontend

  return render(request, 'home.html', context)

def function2(request):

    function1(request) # gets me the results i want to export to excel

    writer.save()
    output.seek(0)

    response = StreamingHttpResponse(output, content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
    response['Content-Disposition'] = f'attachment; filename=customers_{lebook}.xlsx'

  return response
  


I tried to put the code that appears in function2 in function1 and it worked but in the button (validate) that calls function1 yet i want it to run under the function2 button. I want to be able to export the results in function1 using the button (export to excel) that calls function2
my interface with the mentioned buttons
