织梦CMS - 轻松建站从此开始!

沙龙国际_沙龙国际娱乐城_沙龙国际娱乐官网

当前位置: 主页 > 沙龙国际娱乐城 >

flask表单提交无法正常执行流程问题

时间:2017-07-18 03:59来源:未知 作者:admin 点击:
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

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内容


      
      (责任编辑:admin)
织梦二维码生成器
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片
栏目列表
推荐内容