python flask获取前端input输入框中输入内容

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

先看代码如下:

@app.route('/api/users', methods=['POST'])
def register_user():
    dbengine.connection(**dbconnect)
    finduser = users()
    allusers = finduser.find_by('order by id desc')
    newid = newnowid(allusers)
    newpw = request.form.get('password1')
    newemail = request.form.get('email')
    newname = request.form.get('name')
    newuser = users(id=newid, email=newemail, password=newpw, admin=0, name=newname, image="http://www.gravatar.com/avatar/12?d=mm&s=120", created_at=nowdate())
    try:
        newuser.insert()
        dbengine.closeconnection()
        return render_template('register_success.html')
    except Exception:
        print "Exception: register failed"
        dbengine.closeconnection()
        return render_template('register_failed.html')

从代码中可以看到,利用request.form.get()语句便能够获取前端输入内容。

转载于:https://my.oschina.net/u/3636678/blog/2209544

你可能感兴趣的:(python flask获取前端input输入框中输入内容)