2016-06-18 2 views
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)) 

답변

0

/userprofile에서 허용하는 방법을 확인하십시오. 이 뷰 기능은 게시물 요청 만 수락하도록 설정되어 있습니까?

updateaprof()에서 리디렉션 브라우저는, GET 요청을 수락하지 않는 405 방법은 당신이 보는 것을 허용하지 반환합니다 경우 새 위치 /userprofile,에 GET 요청을 발행하게됩니다.

이 경우 문제가 발생하면 지원되는 방법에 GET을 추가하고보기에서 GET 요청을 처리하여 해결할 수 있습니다.

/에도 '색인'URL에 대한 GET 요청을 지원하지 않는 것이 일반적이긴하지만 비슷한 문제가있을 수 있습니다.

+0

위의 userprofle() 메소드를 확인하십시오. 문제가 있습니까? –

+0

@LOKESHTIWARI : 아마도 그렇지 않습니다. '/'도 확인 했습니까? 또한, updateaprof()의'SELECT' 질의는 틀린 것처럼 보입니다. 튜플을'execute()'에 전달해야합니다. 이 코드는 예외를 일으켜서'/ userprofile' 로의 리다이렉트가 일어나지 않을 것입니다. 아마도 문제는 실제로'/'에 있습니다. 마침내 커서와 쿼리 사이의 연결을 닫을 필요도없고'SELECT' 후에 커밋 할 필요도 없습니다. 서버를 다시 시작한 후 – mhawke

+0

코드를 다시 작성한 후 작동 중입니다. 또한 내가 커서, 연결을 제거하고 쿼리를 승/질의. 나를 도와 주셔서 고맙습니다 :) –

관련 문제