How to export Excel from Database in Django 1.7

  1. Install xlwt
pip install xlwt
  1. Create Database Item

  2. Export Excel in Views

    def export_item_list(request):
     wb=xlwt.Workbook(uncoding="utf-8")
     sheet=wb.add_sheet("ITEMS")
     sheet.write(0,0,"code")
     sheet.write(0,1,"name")
    
     row=1
     for item in Item.objects.all():
         sheet.write(row,0,item.code)
         sheet.write(row,1,item.name)
         row=row+1
     response=HttpResponse(content_type="application/vnd.ms-excel")
     response['Content-Description']="attachment;filename=EXCEL_NAME.xls"
     wb.save(response)
     return response