[英]Python flask not displaying HTML file
I am using a JSON file that consists of various job details.我正在使用包含各种工作详细信息的 JSON 文件。 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.这个 JSON 文件在我的存储库中,所以我正在使用
response = requests.get('https://github.com/myname/Beatiful-Soup/blob/main/jsonFile.json')
我必须将此响应转换为 JSON 文件为了在我的 HTML 文件中显示这些工作详细信息。 I set up the flask environment and everything but by some reason my HTML file not displaying any information.我设置了 flask 环境和所有内容,但由于某种原因,我的 HTML 文件没有显示任何信息。 How could I fix that?
我该如何解决?
below is my Python, and 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>
my webpage displays only {{message}}我的网页只显示{{message}}
You are setting message to a string, not your actual data.您正在将消息设置为字符串,而不是您的实际数据。 Try this:
尝试这个:
return render_template('index.html', message=data)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.