variables - 通过在导出 pdf 名称中包含变量来保存到目录路径
问题描述
我正在尝试在 Python 上使用 Weasyprint 和 Jinja2 导出 pdf。保存和导出 pdf 工作正常,但问题是我想将变量传递到路径中。因此,我的变量是“标题”,我希望我所有的 pdf 都采用“标题”变量并将其导出。
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 但变量没有出现在名称中。谢谢你的帮助。
解决方案
推荐阅读
- angular - formBuilder 控件的 setValue() 和 patchValue() 方法在 cordova 插件的方法调用中不起作用
- unity3d - 在 Unity3d 中切换渲染器的纹理
- vue.js - vuejs 和 vuetify(CRUD 操作)
- r - 将 Sys.time() 转换为字符而不丢失时区?
- java - Python客户端不接收来自Spring websocket服务器的消息
- python - 如何强制 python 可重现?
- c++ - 使用正则表达式在 C++ 中排除子文件夹
- javascript - 传单 JS Cluster Maker 捕获 ids 孩子
- python - Color network graph node lines on click in Bokeh, Python
- r - 用函数创建矩阵