[英]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. 我无法通过POST请求使用html表单中的用户输入在数据库中创建新记录。 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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.