Django~Excel,PDF

  1. # Text file
  2. #response = HttpResponse(mimetype='text/plain') 
  3. #response['Content-Disposition'] = 'attachment; filename=my.txt' 
  4. #response.write("aa/n")
  5. #response.write("bb")

 

导出Excel

def some_view(request):
    response=HttpResponse(content_type='text/csv')
    response['Content-Disposition']='attachment;filename="somefilename.csv"'
    
    writer=csv.writer(response)
    writer.writerow(['First row','Foo','Bar','BazLynn'])
    writer.writerow(['Second row','A','B','C','"Testing"',"Here's a quote"])

    return response

 

 

导出PDF

先安装ReportLab

https://pypi.python.org/pypi/reportlab

Python2.7

reportlab-3.3.0-cp27-none-win32

解压后内容

image

安装

pip install reportlab

some_view

 

https://docs.djangoproject.com/en/1.9/howto/outputting-pdf/


Pip解压

pip is already installed if you're using Python 2 >=2.7.9 or Python 3 >=3.4 downloaded from python.org, but you'll need to upgrade pip.

 

WIN: python -m pip install -U pip
https://pip.pypa.io/en/latest/installing/#upgrading-pip
Linux/OX:pip install -U pip

 

image

 

查看版本 pip list

image

 


posted @ 2016-03-16 13:46  南湖鹄  阅读(309)  评论(0编辑  收藏  举报