小编Ola*_*ale的帖子

使用 Python Flask 将 html 转换为 pdf

这是我在 myclass.py 中的代码

class Pdf():

    def render_pdf(self,name,html):


        from xhtml2pdf import pisa
        from StringIO import StringIO

        pdf = StringIO()

        pisa.CreatePDF(StringIO(html), pdf)

        return pdf
Run Code Online (Sandbox Code Playgroud)

我像这样在 api.py 中调用它

@app.route('/invoice/<business_name>/<tin>', methods=['GET'])
def view_invoice(business_name,tin):

   #pdf = StringIO()
  html = render_template('certificate.html', business_name=business_name,tin=tin)
file_class = Pdf()
pdf = file_class.render_pdf(business_name,html)
return pdf
Run Code Online (Sandbox Code Playgroud)

但它抛出这个错误

AttributeError: StringIO instance has no __call__ method
Run Code Online (Sandbox Code Playgroud)

python flask

2
推荐指数
1
解决办法
3022
查看次数

标签 统计

flask ×1

python ×1