我有一個 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 的值并在此處顯示它,而不僅僅是顯示上面的內容?
添加回答
舉報
0/150
提交
取消