亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

當我使用 Flask 渲染模板時,為什么我的 html 代碼沒有輸出變量的值?

當我使用 Flask 渲染模板時,為什么我的 html 代碼沒有輸出變量的值?

藍山帝景 2022-11-09 16:26:55
我有一個 main.py 文件和一個模板文件夾,在我有 math.html 的模板文件夾內。它只是一個基本的 html 文件。在 main.py 中,我正在渲染名為 math.html 的模板。請注意,我使用的是 Flask。這是我的 main.py:from flask import Flask, render_templateimport randomapp = Flask(__name__)@app.route('/')def home():    return render_template('index.html')@app.route('/math-game')def game():  # This is the function which renders math.html    num1 = random.randint(0, 100)    num2 = random.randint(0, 100)    return render_template('math.html', num1=num1, num2=num2)而在我的 math.html 中,我有以下代碼:    <!DOCTYPE html><html><head>    <meta charset="UTF-8">    <title>Math Game</title></head><body><center><h1>Math Game</h1></center><h2>What is {{ num1 }} + {{ num2 }}?</h2></body></html>當我在我的網站上檢查輸出時,它只顯示“什么是 {{ num1 }} + {{ num2 }}?”。為什么不從 main.py 中獲取 num1 和 num2 的值并在此處顯示它,而不僅僅是顯示上面的內容?
查看完整描述

1 回答

?
鳳凰求蠱

TA貢獻1825條經驗 獲得超4個贊

嘗試這樣做http://localhoat:5000/math-game

不要打開 math-game.html,因為這會加載 .html.file 并且不會讀取 {{ }}


查看完整回答
反對 回復 2022-11-09
  • 1 回答
  • 0 關注
  • 111 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號