简体   繁体   中英

Flask/SQLAlchemy error inserting record to database

I am unable to create a new record in the database using the user input from the html form via post request. I get an error message "Bad Request The browser (or proxy) sent a request that this server could not understand."

@app.route("/create_profile", methods=['GET','POST'])
def create_profile():
    if request.method == 'POST':
      n = request.form['name']
      z = request.form['zipcode']
      i1 = request.form['dancing']
      i2 = request.form['football']
      i3 = request.form['art']
      u = User(name=n, zipcode=z, inter1=i1, inter2=i2, inter3=i3 )
      db.session.add(u)
      db.session.commit
    return render_template("create_profile.html")

正如@BurhanKhalidin指出的那样,在调用commit()函数时,应该添加缺少的括号: db.session.commit()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM