我有一个要在 python 中的画布上显示的表格,我在画布中显示了文本,我正在返回缓冲区以在另一个函数中返回一个新的 FileResponse。我的代码:
def Report(dict):
from reportlab.lib.utils import ImageReader
buffer = io.BytesIO()
p = canvas.Canvas(buffer)
textobject = p.beginText()
textobject.setTextOrigin(200, 680)
textobject.textLine('Title')
p.drawText(textobject)
logo = ImageReader('static/img/logo.png')
p.drawImage(logo, 100, 700,width = 400,height=100,mask = None)
data = [['00', '01', '02', '03', '04'],
['10', '11', '12', '13', '14'],
['20', '21', '22', '23', '24'],
['30', '31', '32', '33', '34']]
f = Table(data)
f.setStyle(TableStyle([('BACKGROUND', (1, 1), (-2, -2),
colors.green),
('TEXTCOLOR', (0, 0), (1, -1), colors.red)]))
p.showPage()
p.save()
buffer.seek(0)
return buffer
Run Code Online (Sandbox Code Playgroud) 我试图在 javascript 中加载 django 内的 csv 文件,但它给了我一个错误:http://127.0.0.1:8000/data.csv is not find , data.csv 位置位于包含 html 页面的 templates 文件夹内。
我的代码:
d3.csv("data.csv", function(d, i, columns) {
for (var i = 1, n = columns.length; i < n; ++i)
d[columns[i]] = +d[columns[i]];
return d;
}, function(error, data) {
if (error) throw error;
}
Run Code Online (Sandbox Code Playgroud)