2 回答

TA貢獻1934條經驗 獲得超2個贊
下面的代碼用于 Restful API,因此它以字符串而不是 HTML 的形式返回渲染
app = Flask(__name__, 8080)
api = Api(app)
class New_Info(Resource):
def get(self):
random = exc.runner()
return render_template('test3.html',book_title=random['title'],book_author=random['author'],book_text=random['text'])
api.add_resource(New_Info, '/pretty')
此代碼正確呈現 html
app = Flask(__name__, 8080)
@app.route('/pretty')
def New_Info():
random = exc.runner()
return render_template('test3.html',book_title=random['title'],book_author=random['author'],book_text=random['text'])

TA貢獻1859條經驗 獲得超6個贊
可能不是唯一的問題,但這可能是由于無效的 HTML:
<!DOCTYPE html>
<html>
<h1>
<title>{{book_title}}</title>
</h1>
<h2>
<title>{{book_author}}
</h2>
<body>
<li>{{book_text}}</li>
</body>
</html>
標簽<title>進入<head>并且是唯一的。其他標簽(如<h1>)屬于<body>. 嘗試這個:
<!DOCTYPE html>
<html>
<head>
<title>{{book_title}}</title>
</head>
<body>
<h1>
{{book_title}}
</h1>
<h2>
{{book_author}}
</h2>
<div>
{{book_text}}
</div>
</body>
</html>
需要查看您的視圖函數以檢查其余代碼。也許還有你的app.yaml
添加回答
舉報