Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python提交按钮问题_Python_Flask_Flask Wtforms - Fatal编程技术网

Python提交按钮问题

Python提交按钮问题,python,flask,flask-wtforms,Python,Flask,Flask Wtforms,“发送…”按钮不工作,索引页正在运行,下拉菜单确定,但当我单击“发送…”时,什么也没有发生。(Result.html是可以的,但当然是空的)你知道有什么问题吗 我有这些.py文件: from flask import Flask, request, render_template from flask_wtf import Form from flask_wtf import FlaskForm app = Flask(__name__) @app.route('/', methods=['

“发送…”按钮不工作,索引页正在运行,下拉菜单确定,但当我单击“发送…”时,什么也没有发生。(Result.html是可以的,但当然是空的)你知道有什么问题吗

我有这些.py文件:

from flask import Flask, request, render_template
from flask_wtf import Form
from flask_wtf import FlaskForm

app = Flask(__name__)

@app.route('/', methods=['POST', 'GET'])
def index():
    return render_template('index.html')

@app.route('/result/', methods=['POST', 'GET'])
def result():
    vehicle = request.form.get('wine')
    year = request.form.get('year')
    return render_template('result.html', vehicle=vehicle, year=year)
当然还有两个.html。index.html:

<!DOCTYPE html>
<html>

<body>
<h1>Submitting</h1>

<form action="/result" method="POST">
    <label for="wine">wine</label>
    <select id="wine" name="wine">
      <option>red</option>
      <option>white</option>
      <option>rose</option>
    </select>

    <label for="year">Year</label>
    <select id="year"name="year">
      <option>1972</option>
      <option>1999</option>
      <option>2010</option>
    </select>
</form>

<br>
<button type="submit" value="submit">send...</button>
</body>
</html>

提交
葡萄酒
红色
白色
玫瑰
年
1972
1999
2010

发送。。。
result.html:

<!DOCTYPE html>
<html>
    <body>
        {{ vehicle }} {{ year }}
    </body>
</html>

{{vehicle}{{year}

也许您需要将
按钮
放入
表单
标签中

<form action="/result" method="POST">
    ...
    <button type="submit" value="submit">send...</button>
</form>

...
发送。。。

用此HTML替换您的HTML。您需要将submit按钮放在表单标签中才能使其工作


提交
葡萄酒
红色
白色
玫瑰
年
1972
1999
2010
发送。。。


我在所有地方将“车辆”改为“葡萄酒”后,问题都是一样的:“发送…”不起作用。感谢您的帮助!这就是问题所在。:-)
<body>
<h1>Submitting</h1>

<form action="/result" method="POST">
    <label for="wine">wine</label>
    <select id="wine" name="wine">
      <option>red</option>
      <option>white</option>
      <option>rose</option>
    </select>

    <label for="year">Year</label>
    <select id="year"name="year">
      <option>1972</option>
      <option>1999</option>
      <option>2010</option>
    </select>
    <button type="submit" value="submit">send...</button>

</form>

<br>
</body>
</html>