python - Pdfkit 没有在 Flask 中将我的 Pygal svg 图转换为 pdf
问题描述
我使用 Pygal 绘制了条形图,但是当我使用命令时pdfkit.from_string(....)
这是我的代码片段(routes.py 文件)
@app.route('/home', methods=['POST'])
def get_pdf():
products=['A', 'B', 'C']
quants=[200,50,50]
line_chart = pygal.Bar()
line_chart.title = 'Stock Availability'
line_chart.x_labels = products
line_chart.add('Products',quants)
line_chart = line_chart.render_data_uri()
x='name'
rendered = render_template('inventoryAdmin/status.html',status_list=status_list, cD=countDictionary, line_chart=line_chart)
pdf = pdfkit.from_string(rendered, False, configuration=config, options=kitoptions)
response = make_response(pdf)
response.headers['content-Type']='application/pdf'
response.headers['Content-Disposition']='attached; filename=.pdf'
return response
return redirect(url_for('status'))
这是我的 .html 文件
<div class="container">
<legend class="border-bottom mb-4">Unallocated Items</legend>
<div class="container" align="left">
<embed type="image/svg+xml" src={{line_chart|safe}} style='max-width:1000px'/>
</div>
</div>
我应该怎么做才能使图表可见?
解决方案
推荐阅读
- c# - Xamarin 依赖服务
- c - 如何使用数组查找列中多个值的积分?
- microservices - 如何使用 Lagom 设置域模型?
- ansible - 如何在 ansible.cfg 中设置默认详细程度
- sql-server - 如何在 SQL Server docker 映像之上安装 PowerShell Core?
- postgresql - 如何在谷歌云中部署 postgresql 服务器
- discord.js - ReferenceError:公会未定义
- java - 服务器问候完成后的 TLS 握手错误
- android - 如何在不滚动 Android Studio 的情况下查看我的所有代码?(我的意思是一页中的所有代码无需滚动)
- python - 显示从十进制到二进制转换的 Python 代码