当我从选择字段中选择数据并按“选择”(提交)时,我得到“不允许使用方法”。为什么?
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方法:
相关问题 更多 >
编程相关推荐