0
POST 메서드를 사용하여이 간단한 폼 데이터를 MySQL 데이터베이스로 보내려고합니다. 하지만 같은 오류 "메서드가 허용되지", 나는 그게 잘못인지 모르겠다. 제발 도와주세요.Flask - 405, 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))
USERPROFILE 경로 :
@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))
위의 userprofle() 메소드를 확인하십시오. 문제가 있습니까? –
@LOKESHTIWARI : 아마도 그렇지 않습니다. '/'도 확인 했습니까? 또한, updateaprof()의'SELECT' 질의는 틀린 것처럼 보입니다. 튜플을'execute()'에 전달해야합니다. 이 코드는 예외를 일으켜서'/ userprofile' 로의 리다이렉트가 일어나지 않을 것입니다. 아마도 문제는 실제로'/'에 있습니다. 마침내 커서와 쿼리 사이의 연결을 닫을 필요도없고'SELECT' 후에 커밋 할 필요도 없습니다. 서버를 다시 시작한 후 – mhawke
코드를 다시 작성한 후 작동 중입니다. 또한 내가 커서, 연결을 제거하고 쿼리를 승/질의. 나를 도와 주셔서 고맙습니다 :) –