[英]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.