[英]Python flask application not displaying generated html file for second time
[英]Python flask not displaying HTML file
我正在使用包含各種工作詳細信息的 JSON 文件。 這個 JSON 文件在我的存儲庫中,所以我正在使用response = requests.get('https://github.com/myname/Beatiful-Soup/blob/main/jsonFile.json')
我必須將此響應轉換為 JSON 文件為了在我的 HTML 文件中顯示這些工作詳細信息。 我設置了 flask 環境和所有內容,但由於某種原因,我的 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>
我的網頁只顯示{{message}}
您正在將消息設置為字符串,而不是您的實際數據。 嘗試這個:
return render_template('index.html', message=data)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.