0
我是新來的燒瓶,並且遇到困難,保存從四種不同的咖啡烘焙選項中選擇的值並將其顯示在另一頁上。一個頁面(Roast.html)用戶可以選擇從Light,Medium,Dark和Special中選擇一個咖啡烘焙。按下提交按鈕後,我想在下一頁(Brew.html)上顯示該選擇,即「你的_____烘焙咖啡現在正在釀造!」任何幫助將不勝感激!我寧願不在這個代碼中涉及php或javascript。謝謝燒瓶從字段中保存選定的值並在另一頁上顯示
coffeeMaker.py:
from flask import Flask
from flask import render_template
from flask import url_for
from flask import request
app = Flask(__name__)
@app.route('/')
def welcome():
return render_template("welcome.html")
@app.route('/Roast', methods = ['GET','POST'])
def roast():
print "inside Roast"
return render_template("Roast.html")
@app.route('/Brew', methods = ['GET','POST'])
def brew():
if request.method == 'POST':
print 456
a = request.query_string
print 789
return render_template("Brew.html",selection = a)
else:
return "This is a GET request."
if __name__ == '__main__':
app.run()
welcome.html:
<html>
<head>
<title>Welcome to Coffee Maker</title>
</head>
<body>
<h1>This is a website for you to order your coffee of perference
</h1>
<a href = "/Roast" >ready for a coffee</a>
</body>
</html>
Roast.html:
<html>
<form action="/Brew" method="Post">
<h3>2. Choose your Roast</h3>
<input type="text" name="firstname" value="Mickey">
<br>
<input type="radio" name="roastType" value="Light">Light
<br>
<input type="radio" name="roastType" value="Medium" checked>Medium
<br>
<input type="radio" name="roastType" value="Dark">Dark
<br>
<input type="radio" name="roastType" value="HackGT Blend">Special Blend
<br><br>
<input type="submit" value="Brew It">
</form>
</html>
Brew.html:
<html>
<head>
<title>
brew
</title>
</head>
<body>
<h1> Brewing</h1>
<p>You selected{{selection}}</p>
<p>Get ready for your perfect cup of coffee~</p>
</body>
</html>