python - 从 django 上的网站下载文件
问题描述
我在 debian 服务器上有一个网站。我用docx格式填写模板并保存。如何将其下载到用户的设备?
post_data = json.loads(request.body)
date = post_data.get('date', False)
price = post_data.get('price', False)
pricesum = post_data.get('pricesum', False)
startdate = post_data.get('startdate', False)
enddate = post_data.get('enddate', False)
doc = DocxTemplate('template.docx')
dates = date
prices = price
tbl_contents = [{'expirationdate': expirationdate, 'price': price}
for expirationdate, price in zip(dates, prices)]
context = {
'tbl_contents': tbl_contents,
'finalprice': sum(prices),
'startdate': startdate,
'enddate': enddate
}
doc.render(context)
doc.save("static.docx")
解决方案
推荐阅读
- azure - 从 Azure DevOps 中的提交哈希获取拉取请求 ID
- database - 将 IoTDB 从 0.11.x 升级到 0.12.2 后无法使用标签/属性查询时间序列
- node.js - 几天后,我无法再启动 Puppeteer,直到我重新启动服务器
- java - spring boot 在 docker linux 环境中构建进度的 JAR 文件在哪里...?
- javascript - 用于高阶函数的带有 tsd-jsdoc 的 JSDoc 输出错误
- typescript - 打字稿类型 gurad 在某些特定情况下不起作用
- wpf - 富文本框超链接路径已更改,无法正常工作。(带有超链接的 WPF 富文本框 -> RTF 保存 -> 将 RTF 读取到富文本框)
- javascript - 无法在 laravel 视图中访问已安装的 npm 包
- sql - 老化的 SQL 查询显示不正确的语法
- excel - 将 1 个工作簿中的表复制到另一个工作簿