Im trying to implement a pdf report downloader with fpdf
def download_report():
try:
conn= db.connection
cursor = conn.cursor(pymysql.cursors.DictCursor)
sql= "SELECT * FROM productos"
cursor.execute(sql)
result= cursor.fetchall()
print(result)
pdf= FPDF()
pdf.add_page()
page_width = pdf.w -2 * pdf.l_margin
pdf.set_font('Times', 'B', 14.0)
pdf.cell(page_width, 0.0, 'Productos 2022 Listado',align='C')
pdf.ln(10)
pdf.set_font('Courier', '', 12)
col_width = page_width/4
pdf.ln(1)
th =pdf.font_size
for row in result:
pdf.cell(col_width, th, str(row['idProducto']), border=1)
pdf.cell(col_width, th, row['name'], border=1)
pdf.cell(col_width, th, row['precio'], border=1)
pdf.cell(col_width, th, row['imagen'], border=1)
pdf.ln(th)
pdf.ln(10)
pdf.set_font('Times', '', 10.0)
pdf.cell(page_width, 0.0, '- fin del listado -',align='C')
return Response(pdf.output(dest='S').encode('latin-1'), mimetype='application/pdf', headers={'Content-Disposition':'attachment;filename=productos_listado.pdf'})
except Exception as e:
print(e)
But I keep having this error message
'Connection' object is not callable"
I'm working with flask_mysqldb, (I've seen similiar errors but they've been working with MYSQLalchemy, not my case).
source https://stackoverflow.com/questions/73085036/problem-with-mysql-connection-python-flask
Comments
Post a Comment