简体   繁体   中英

Why isn't my else in flask python not working?

When I press the start button it directs me to error.html even if I choose my skin type

from flask import Flask, render_template, request

app = Flask(__name__)

SKIN = ["Oily" , "Dry" ,"Sensitive", "Combination", "Normal"]

@app.route("/")
def index():
   return render_template("index.html", skins=SKIN)

@app.route("/register", methods=["POST"])
def register():
   skin = request.form.get("skin")
   if not skin:
      return render_template("error.html")
   else:
      return render_template("info.html")

The problem I see is that your input is name="skin type" , whereas you are checking for an input named skin .

If you change the input to name="skin" it should work.

I also suggest in the future that you do not use spaces in any input field names.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM