gpt4 book ai didi

javascript - 将pdf从python(pyramid)发送到jquery ajax

转载 作者:行者123 更新时间:2023-11-28 05:56:26 25 4
gpt4 key购买 nike

如何发送可渲染的PDF文件到jinja2?如果可能的话,编写代码 (.py) 和 (.js)。这是我的 ajax 代码

$("#print").click(function(event) {
$.ajax(
{
type: "POST",
url: "/printledgerreport",
global: false,
async: false,
dataType : 'json',
//contentType : 'application/pdf'

data: {"backflag":0,"accountcode":$("#accountcode").val(),"calculatefrom":$("#calculatefrom").val(), "calculateto":$("#calculateto").val(),"financialstart":sessionStorage.yyyymmddyear1,"projectcode":$("#projectcode").val(),"monthlyflag":false,"narrationflag":false},
beforeSend: function(xhr)
{
xhr.setRequestHeader('gktoken',sessionStorage.gktoken );
},
success: function(data){
window.open("ledgerReport.pdf");
}
});
});

请告诉我如何编写 Pyramid 代码

现在这是我的新 Pyramid 代码:

@view_config(route_name="printledgerreport", renderer="")
def printLedgerReport(request):
filepath = ("ledgerReport.pdf")
response = FileResponse(filepath)
response.headers['Content-Disposition'] = ("attachment; filename=ledgerReport.pdf")
return response

最佳答案

试试这个。我已经喝了第五杯玛格丽特了。它应该有效。 :) 请记住添加“download_PDF”的路由。

@view_config(route_name="download_PDF", renderer="")
def download_view(request):
filepath = ("pathtomyfile/test.pdf")
response = FileResponse(filepath)
response.headers['Content-Disposition'] = ("attachment; filename=test.pdf")
return response

哎呀。这只是下载文件。也许你可以让它与 jinja 一起工作。再次。玛格丽塔太多了:)

关于javascript - 将pdf从python(pyramid)发送到jquery ajax,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37634936/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com