通过在导出pdf名称中包含变量来保存到目录路径

时间:2019-05-10 09:10:46

标签: variables pdf export weasyprint

我正在尝试在Python上使用Weasyprint和Jinja2导出pdf。保存和导出pdf可以正常工作,但是问题是我想将变量传递到路径中。因此,我的变量是'title',我希望我的所有pdf都采用'title'变量并将其导出。

title = df.iloc[1,0] #created my title variable

template_vars = {"title": title, "start_date": start_date, "end_date": end_date, "price": price, 
                 "total_Impressions": total_impressions, "art_work": art_work, "total_Clicks": total_clicks,
                 "cpm":cpm, "image_path": image_path} #created my dictionary 

html_out = template.render(template_vars)
print(html_out) #rendered my template

HTML(string=html_out).write_pdf("D:/Course/learning-automation/{title}.pdf",
    stylesheets=[CSS('D:/Course/learning-automation/style.css')]) # tried to enter the title variable in the exported pdf path. 

实际结果是导出了pdf,但该变量未出现在名称中。感谢您的帮助。

0 个答案:

没有答案