def certificate(): id = request.args.get('id') donor = Donor.query.filter(Donor.id == id).first() file_dir = os.path.join(basedir, app.config['IMG_FOLDER']) if donor: no = "WH2020012310{0:04d}".format(donor.id) certi_file = "%s.png" % os.path.join(file_dir, no) if not os.path.exists(certi_file): amount = "%.2f" % donor.amount cert = Certificate(donor.name, amount, no) cert.grant() image_data = open(certi_file, "rb").read() response = make_response(image_data) response.headers['Content-Type'] = 'image/png' return response