python flask獲取前端input輸入框中輸入內容

先看代碼以下:html

@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()語句便可以獲取前端輸入內容。前端

相關文章
相關標籤/搜索