1、代码
from flask import Flask
from wtforms import TextAreaField,Form,validators,SubmitField
from flask import render_template,request,redirect,url_for,flash
app = Flask(__name__)
class CmdForm(Form):
cmdText = TextAreaField('command input')
submit = SubmitField('submit')
@app.route('/')
def hello_world():
return 'Hello World!'
@app.route('/command',methods=['GET', 'POST'])
def sss():
myform = CmdForm(request.form)
if request.method == 'POST':
cmd = myform.cmdText.data
return render_template('index.html',message=cmd,form=myform)
return render_template('index.html',form=myform)
if __name__ == '__main__':
app.run(debug=True)
一开始是这样的空表单
提交后,内容是显示出来了,但是表单了填的东西还在
要怎么处理,才能使得表单提交后,内容显示出来,然后表单置为空的?
myForm.cmdText.data=None 返回之前将数据清除,再render,不过我下午测试好像对IntegerField无效