[英]Flask - 405, Method not allowed
我正在嘗試使用POST方法將此簡單表單數據發送到MySQL數據庫。 但是同樣的錯誤“方法不允許”,我不知道這是怎么回事。 請幫我在這里。
HTML代碼:
<form role="form" action='/updateabbprof' method="POST">
<div class="form-group">
<label class="control-label">About Us</label>
<textarea class="form-control" name="updabt" id="editabt"></textarea>
</div>
<div class="form-group">
<button id="aupdate" type="submit" class="btn btn-primary">Save</button>
</div>
</form>
</div>
燒瓶:
app.route('/updateabbprof', methods = ['POST'])
def updateaprof():
try:
if session.get('user'):
_userid = session.get('user')
_userabt = str(request.form['updabt'])
#if _userid or _username or _email or _phone:
con = mysql.connect()
cursor = con.cursor()
cursor.execute("""UPDATE user_signpp SET user_abt = %s WHERE Id =%s""",(_userabt,_userid))
con.commit()
cursor.close()
con.close()
con = mysql.connect()
cursor = con.cursor()
cursor.execute("""SELECT * FROM user_signpp WHERE Id = %s""",(_userid))
con.commit()
datanew = cursor.fetchall()
session['msg'] = list(datanew[0])
cursor.close()
con.close()
return redirect("/userprofile")
else:
return redirect('/')
except Exception as e:
return render_template('error.html', error = str(e))
用戶個人資料路線:
@app.route('/userprofile', methods = ['GET','POST'])
def userprofile():
try:
if session.get('user'):
return render_template('profile.html', msg = session.get('msg'))
else:
return redirect('/')
except Exception as e:
return render_template('error.html', error = str(e))
檢查/userprofile
接受的方法。 可能此查看功能設置為僅接受發布請求?
從updateaprof()
重定向將導致瀏覽器向新位置/userprofile
發出GET
請求,如果它不接受GET請求,則將返回您看到的405 Method Not Allowed。
如果這是問題,可以通過將GET
添加到受支持的方法並在視圖中處理GET請求來解決。
/
可能也有類似的問題,盡管通常不支持“索引” URL上的GET請求。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.