I have a flask page that downloads a PDF as part of the return statement, but I'd also like to return some text to display on the website. Is it possible to return two things, such as?:
return send_file('test.pdf', as_attachment=True), "this is what the webpage displays"
I have also tried it as a separate function, but nothing downloads. The download works fine if I remove just use this as part of the pdf()
function:
return send_file('test.pdf', as_attachment=True)
Full code:
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()