title: How to export data in python with excel format?
body: <h1>views.py</h1>
  
  <pre><code>def export_to_excel(request):
  
      lists = MyModel.objects.all()
  
      # your excel html format
      template_name = "sample_excel_format.html"
  
      response = render_to_response(template_name, {'lists': lists})
  
      # this is the output file
      filename = "model.csv"
  
      response['Content-Disposition'] = 'attachment; filename='+filename
      response['Content-Type'] = 'application/vnd.ms-excel; charset=utf-16'
      return response
  </code></pre>
  
  <h1>urls.py</h1>
  
  <pre><code>from django.conf.urls.defaults import *
  
  urlpatterns = patterns('app_name.views',
     url(r'^export/$', 'export_to_excel', name='export_to_excel'),  
  )
  </code></pre>
  
  <ol>
  <li>Last, in your page create a button or link that will point in exporting.</li>
  </ol>
  
  <h1>page.html</h1>
  
  <pre><code>&lt;a href="{% url app_name:export_to_excel %}"&gt;Export&lt;/a&gt;
  </code></pre>
  
  <p>Nothing getting file option for download and not giving any error  but i can see all result in log its working fine.</p>