我是编码的新手,我很难在if语句中尝试使用session ['answer']。基本上,如果用户输入的值低于随机生成的值,我希望呈现某个页面,如果更高,则会呈现不同的页面。我的if语句似乎不起作用,'resultHigh.html'页面是唯一被渲染的页面。希望这很清楚。以下是我的代码:
from flask import Flask, session, redirect, render_template, request
app = Flask(__name__)
app.secret_key = "Secret"
@app.route("/")
def index():
return render_template('index.html')
@app.route('/guess', methods=['POST'])
def guess():
import random
num = random.randrange(0, 100)
session['answer'] = request.form['answer']
if session['answer'] > num:
y = 'resultHigh.html'
elif session['answer'] < num:
y = 'resultLow.html'
return render_template(y)
app.run(debug=True)