我有一个烧瓶页面,下载PDF作为return语句的一部分,但我还想返回一些文本显示在网站上。是否可以返回两件事,例如?:
return send_file('test.pdf', as_attachment=True), "this is what the webpage displays"
我也尝试过它作为一个单独的功能,但没有下载。下载工作正常,如果我删除只是使用它作为pdf()
函数的一部分:
return send_file('test.pdf', as_attachment=True)
完整代码:
from reportlab.lib.enums import TA_JUSTIFY
from reportlab.lib.pagesizes import letter
from reportlab.platypus import SimpleDocTemplate, Paragraph
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from flask import Flask, send_file
app = Flask(__name__)
@app.route('/')
def pdf():
global doc
doc = SimpleDocTemplate("test.pdf",pagesize=letter)
Story=[]
styles=getSampleStyleSheet()
styles.add(ParagraphStyle(name='Justify', alignment=TA_JUSTIFY))
ptext = '<font size=12>test</font>'
Story.append(Paragraph(ptext, styles["Justify"]))
doc.build(Story)
def download():
global doc
return send_file('test.pdf', as_attachment=True)
download()
return "this is what the webpage displays"
app.run()