首页 > 解决方案 > Flask 渲染模板

问题描述

我尝试将数据插入到我的模板 render_template。

data = Bill.bill_data(self)
        return render_template('templates/bill.html', **data)

文件夹模板中的账单模板位置。但我有这个错误

jinja2.exceptions.TemplateNotFound: templates/bill.html

我的数据如下所示:

data={
        "payer_currency": "5",
        "shop_amount": "5",
        "shop_currency": "5",
        "shop_id": "5",
        "shop_order_id": "12",
        "sign": ""
        }

标签: pythonflaskjinja2

解决方案


您不必添加templates/路径。作为文件夹中的默认render_template搜索模板templates

return render_template('bill.html', **data)

推荐阅读