我想在我的网站上有一个页面,其中有多个按钮可以发送不同的 POST 请求来修改我的数据库的某些部分。
目前,只有顶部的 if 语句被执行。如果我尝试下面的两个,我得到:浏览器(或代理)发送了一个该服务器无法理解的请求。
如果我切换它们,它总是最上面的 if 语句被执行。
我这样做错了吗?有没有更好的方法来做这种事情?
@app.route('/', methods=["GET", "POST"])
@login_required
def homepage():
if request.method == "POST" and request.form['estimatedCost']:
_projectName = request.form['projectName']
_estimatedCost = request.form['estimatedCost']
_amountAllocated = request.form['amountAllocated']
conn, cursor = connectDB()
cursor.execute("INSERT INTO `project` (`name`, `estimatedCost`, `amountAllocated`, `pStatus`, `actualCost`, `estimatedDuration`, `actualDuration`, `costDifference`) VALUES ( '" + _projectName + "', '" + _estimatedCost + "', '" + _amountAllocated + "', 'NOT STARTED', 0, 0, 0, NULL)")
conn.commit()
conn.close()
return redirect('/')
if request.method == "POST" and request.form['delete']:
_delete …Run Code Online (Sandbox Code Playgroud)