Flask - 405,方法不允许
Flask - 405, Method not allowed
我正在尝试使用 POST 方法将这个简单的表单数据发送到 MySQL 数据库。但同样的错误 "Method not allowed",我不知道那有什么问题。请帮帮我。
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
接受的方法。可能此视图函数设置为仅接受 post 请求?
来自 updateaprof()
的重定向将导致浏览器向新位置 /userprofile
发出 GET
请求,如果它不接受 GET 请求,将 return 您看到的 405 Method Not Allowed。
如果这是问题,您可以通过将 GET
添加到支持的方法并在您的视图中处理 GET 请求来解决它。
也有可能 /
有类似的问题,尽管在 "index" URL.
上不支持 GET 请求是不常见的
我正在尝试使用 POST 方法将这个简单的表单数据发送到 MySQL 数据库。但同样的错误 "Method not allowed",我不知道那有什么问题。请帮帮我。
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
接受的方法。可能此视图函数设置为仅接受 post 请求?
来自 updateaprof()
的重定向将导致浏览器向新位置 /userprofile
发出 GET
请求,如果它不接受 GET 请求,将 return 您看到的 405 Method Not Allowed。
如果这是问题,您可以通过将 GET
添加到支持的方法并在您的视图中处理 GET 请求来解决它。
也有可能 /
有类似的问题,尽管在 "index" URL.