SelectField 提交方法不允许

SelectField submit Method not allowed

当我从 select 字段中选择数据并按 'Choose'(提交)时,我得到 "Method Not Allowed"。为什么?

run.py

from flask import Flask, render_template, flash
from flask_wtf import FlaskForm
from flask_wtf.csrf import CSRFProtect
from wtforms import SelectField, SubmitField


app = Flask(__name__)
csrf = CSRFProtect(app)

class Config(object):
    SECRET_KEY ='123123123qweasdzxc'

app.config.from_object(Config)

class Exploits(FlaskForm):
    language = SelectField(u'Programming Language', choices=[('cpp', 'C++'), ('py', 'Python'), ('text', 'Plain Text')])
    use = SubmitField('Choose')


@app.route("/")
def home():
    form = Exploits()
    if form.validate_on_submit():
        print('SUBMIT!!!')
        flash('Botton is submited ' + form.language.data)
    return render_template('index.html', form=form)



if __name__ == "__main__":
    app.run(debug=True)

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form action="" method="post" novalidate>
    {{ form.csrf_token }}
    {{ form.language }}
    {{ form.use }}
</form>
</body>
</html>

您需要允许 POST 方法:

@app.route("/", methods=['GET', 'POST'])