Python烧瓶未显示HTML文件

发布于 2025-01-22 22:22:08 字数 1034 浏览 2 评论 0原文

我正在使用一个由各种工作细节组成的JSON文件。这个JSON文件在我的存储库中,所以我正在使用 响应= requests.get('https://github.com/myname/beatifle-soup/blob/main/jsonfile.json')我必须将此响应转换为JSON文件才能显示这些工作详细信息在我的HTML文件上。我设置了烧瓶环境,除了某种原因,我的HTML文件未显示任何信息。我该如何解决?

以下是我的python,html

import json
import requests
from flask import Flask, render_template

# write a code to give call to json file and then render
# html page
app = Flask(__name__)
@app.route("/")
def displayJobDetails():

    response = requests.get('https://github.com/myName/Beatiful-Soup/blob/main/jsonFile.json')
    data = json.loads(response.text);
    return render_template('index.html', message="data")

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8000, debug=True)
<!DOCTYPE html>
<html>
<head>
    <title>Display the Job Details</title>
</head>
<body>
    <div>
    <p> {{ message }}} </p>
    </div>
</body>

</html>

我的网页仅显示{{messages}}

I am using a JSON file that consists of various job details. This JSON file is in my repository so I am using
response = requests.get('https://github.com/myname/Beatiful-Soup/blob/main/jsonFile.json') I have to convert this response to JSON file in order to display these job details on my HTML file. I set up the flask environment and everything but by some reason my HTML file not displaying any information. How could I fix that?

below is my Python, and HTML

import json
import requests
from flask import Flask, render_template

# write a code to give call to json file and then render
# html page
app = Flask(__name__)
@app.route("/")
def displayJobDetails():

    response = requests.get('https://github.com/myName/Beatiful-Soup/blob/main/jsonFile.json')
    data = json.loads(response.text);
    return render_template('index.html', message="data")

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8000, debug=True)
<!DOCTYPE html>
<html>
<head>
    <title>Display the Job Details</title>
</head>
<body>
    <div>
    <p> {{ message }}} </p>
    </div>
</body>

</html>

my webpage displays only {{message}}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

枯寂 2025-01-29 22:22:08

您将消息设置为字符串,而不是您的实际数据。尝试以下操作:

return render_template('index.html', message=data)

You are setting message to a string, not your actual data. Try this:

return render_template('index.html', message=data)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文