有人可以帮我吗? 我是一名新程序员,对于一个小项目,我需要为数据库中的每个用户创建一个个人资料页面
@app.route("/idpage/<int:page_id>", methods=['GET', 'POST'])
def profilepage(page_id):
profile=engine.execute("SELECT username,password FROM tutorial WHERE id=" +page_id+ "").fetchall()
return render_template('viewprofile.html', profile=profile)
错误给了我
TypeError: cannot concatenate 'str' and 'int' objects
这是我的第二个&#34;计划&#34;我可以找到一些使用sql的文档吗?
答案 0 :(得分:3)
您永远不应该通过直接在其中插入用户输入来构建查询。这样,您最多可以SQL injection attacks。相反,您应该使用bind parameters。
engine.execute("SELECT username, password FROM tutorial WHERE id = ?", page_id)
注意,绑定符号因驱动程序而异,但通常是?
或%s
之一。