首页 > 解决方案 > 从 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")

标签: pythondjango

解决方案


推荐阅读