- # Text file
- #response = HttpResponse(mimetype='text/plain')
- #response['Content-Disposition'] = 'attachment; filename=my.txt'
- #response.write("aa/n")
- #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
解压后内容
安装
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
查看版本 pip list