title: Python Django- How to download file on client machine in django project
body: <p>I am new to python,
  I have created a small Django application to download data into excel format. 
  it downloads in a project folder or given path(on the server).</p>
  
  <p>but when I hit the URL from the client machine then it should download on the client machine but it downloads on my server only.
  Please suggest a suitable method(code) to download an excel file on the client machine only.</p>
  
  <p>Thanks in advance.</p>
  
  <p>-------code-------</p>
  
  <pre><code>try:
      cursor = connection.cursor()
      cursor.execute("""select * from table""")
  
      columns = [desc[0] for desc in cursor.description]
      data = cursor.fetchall()
      result = len(data)
      print("No of records :" ,len(data))
      df = pd.DataFrame(list(data), columns=columns)
  
      home = os.path.expanduser("~")
      print('Home path------------',home)
      download_location = os.path.join(home,'Downloads')
      print('download path------------',download_location)
  
      filename = 'django_simple.xlsx'
  
      writer = pd.ExcelWriter(download_location+'/'+ filename)
      df.to_excel(writer, sheet_name='Hundai')
      writer.save()
  
      print("File saved successfully!")
      cursor.close()
  except:
      print("There is an error")    
  finally:
      if (connection):
          connection.close()
          cursor.close()
          print("The MSSQL connection is closed")   
  
  return render(request,'result.html',{'result': result})
  </code></pre>