带有 html 模板的 Flask 变量动态 url

时间:2021-04-20 14:37:52

标签: python flask

在编写一些代码以动态更新页面时。我在尝试渲染页面时遇到了问题。 错误是:

jinja2.exceptions.TemplateNotFound:/html/test.html

这是查找和呈现页面的代码:

        # Open the user file to read from
        url = name
        url_file = open('projects.txt', 'r')
        lines = url_file.readlines()
        # check all lines for matching name
        for line in lines:
            saved_url, maintance, html = line.split("|")
            if saved_url == url:  # if url is the same. print info and display page. adding maintence check after
                print("url:", saved_url, " is in maintence:", maintance, " html template area:", html),
                if maintance == 'false':
                    return render_template(html)

不确定是什么导致了这个错误,或者是否flask只是不喜欢读取模板位置的变量。

模板确实存在。用 /html/index.html 试试这个就可以了。 注意:其余代码有效。就在最后一行。

而且我知道使用任何类型的数据库会更好,但目前这是我必须在其中工作。

编辑 所以代码读取的是来自projects.txt的test|false|/html/test.html。 运行调试时,变量 html 读取为字符串。它的读数 /html/test.html 。 重点是,它应该作为字符串传递。

我将在 html 中为项目创建一个动态更新区域,因为我最初的想法似乎行不通。

0 个答案:

没有答案