准备工作:
安装django-easy-pdf:
pip install django-easy-pdf
django-easy-pdf依赖:
django>=1.10
xhtml2pdf>=0.2b1
reportlab
我当时在windows安装reportlab时直接pip没有成功,可以使用一下命令指定安装源进行安装
pip install reportlab -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
在settings中注册应用
正式开始:
1.先准备一个HTML模板,该模板继承easy_pdf/base.html
{% extends "easy_pdf/base.html" %}
{% block extra_style %}
<style type="text/css">
body {
font-family: "Helvetica", "sans-serif";
color: #333333;
}
</style>
{% endblock %}
{% block content %}
<div id="content