首页 > 解决方案 > Flask render_template() 不会渲染 xhtml,但是当我手动打开它时它会在我的浏览器中正确渲染

问题描述

我正在尝试渲染 xhtml (X3D) 文件。问题是,当通过烧瓶路线渲染这些模板时,一个 xhtml 模板可以正常工作,而另一个不能。当我在浏览器中手动打开它们时,这两个文件都可以正常工作。第二个文件是使用 BeautifulSoup 对第一个文件的修改。

#flask app module
from flask import Flask, render_template

app = Flask(__name__)

@app.route("/")
def hello_world():
    return render_template('index.html')

@app.route('/xhtml')
def xhtml():
    return render_template('8b0e87efd5144053916a1cadfc9c5194.xhtml')

@app.route('/xhtml_2')
def xhtml_2():
    return render_template('920e053d8e474fc1869e9a2c763e9186.xhtml')

if __name__ == '__main__':
    app.run(debug=True)

关于 render_template() 我有什么遗漏吗?

工作文件:https ://pastebin.com/qQi96Fcq

不工作文件:https ://pastebin.com/HJiD9WTZ

两个文件如何呈现的屏幕截图

标签: pythonflaskbeautifulsoupjinja2xhtml

解决方案


这两个文件非常相似,因为第二个文件只是使用 BeatifulSoup 对第一个文件的修改。我玩弄了这些文件并逐步更改了代码块。我想通了,BeautifulSoup 变了

<Viewpoint ... ></Viewpoint>

<Viewpoint ... />

jinja 似乎不喜欢它。更改损坏文件中的这些标签后,它现在可以正确呈现:

<Viewpoint ... > </Viewpoint>

即使没有人能为我解决这个问题,我仍然感谢您的意见,因为它让我更加专注地思考我的问题。


推荐阅读