flask表单提交无法正常执行流程问题
forms.py内容
class GameServerForm(Form):
id = IntegerField('GameServer Id',[DataRequired()])
name = StringField('GameServer Name',[DataRequired()])
host = StringField('GameServer Host',[DataRequired()])
models.py内容
class GameServer(db.Model):
__tablename__ = 'GameServers'
serverId = db.Column(db.Integer,primary_key=True)
serverName = db.Column(db.String(32),unique=True,index=True)
serverHost = db.Column(db.String(64),unique=True,index=True)
views.py内容
@main.route('/addGameServer',methods=['GET','POST'])
def addGameServer():
gameserverform = GameServerForm()
print gameserverform
if gameserverform.validate_on_submit():
gameserver = GameServer.query.filter_by(serverId=gameserverform.id.data).first()
if gameserver is None:
gameserver = GameServer(serverId=gameserverform.id.data,
serverName=gameserverform.name.data,
serverHost=gameserverform.host.data)
print gameserver
db.session.add(gameserver)
db.session.commit()
flash('add server complete')
return redirect(url_for('main.index'))
else:
print 'aaaaaaaaaaaaaa'
else:
print 'out run'
return render_template('addgameser.html',gameserverform=gameserverform)
addgameser.html内容
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3">
{% for message in get_flashed_messages() %}
<div class="alert alert-warning">
<button type="button" class="close" data-dismiss="alert">×</button>
{{ messages }}
</div>
{% endfor %}
</div>
<form class="col-md-6 col-md-offset-3" role="search" method="POST">
<div class="form-group">
{{ gameserverform.id.label }}{{ gameserverform.id(class="form-control",placeholder="id") }}
{{ gameserverform.name.label }}{{ gameserverform.name(class="form-control",placeholder="name") }}
{{ gameserverform.host.label }}{{ gameserverform.host(class="form-control",placeholder="host") }}
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>
</div>
项目起来之后,在表单页面进行提交操作
程序执行的是else里面的内容
也就是没有进入gameserverform.validate_on_submit():这里的操作
这是为什么的?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
额,自己解决了
在html中加了以下内容
就正常了。