我如何将其更改为删除框?我有这个代码,它获取在文本框中输入的用户输入并将其返回到python。
Python代码
@app.route('/signup', methods = ['POST'])
def signup():
make = request.form['make']
model=request.form['model']
print("MAKE" +"= "+ make + "Model"+ "= "+ model)
return redirect('/')
HTML文件:
<form action="/signup" method="post">
<input type="text" name="make"></input>
<input type="text" name="model"></input>
<input type="submit" value="Sumbit"></input>
</form>
我的意思是投递箱:
<select>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
到目前为止我得到了什么:
new html
<!DOCTYPE html>
<html>
<select name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
<input type="submit" value="Submit">
</html>
新代码:
@app.route('/signup', methods = ['POST'])
def signup():
make = request.form['cars']
print(make)
return redirect('/')
答案 0 :(得分:0)
表单元素需要名称 - select
字段的示例:
<select>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
需要更像:
<select name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
现在,您的视图可以通过调用request.form["cars"]