简体   繁体   中英

Flask Post method 405

Why is Post method not being called i can use only get method

@Admin.route("/upload-image",methods=["GET", 'POST']) def upload_image():

if request.method == 'POST':

    if request.files:
        pdf = request.files["pdf"]

        print(pdf)
        return redirect()
return '''<form action="/Admin/upload-image" method='POST'>

    <div class="form-group">
      <label>Select PDF</label>
      <div class="custom-file">
        <input type="file" class="custom-file-input" name="pdf" id="pdf">
        <label class="custom-file-label" for="image">Select PDF</label>
      </div>
    </div>

    <button type="submit" class="btn btn-primary">Upload</button>
  </form>'''

I get a similar issue in my project and this is the solution I found:-)

Get call for login

@app.route("/login")
   def getCall():
     response = {}
     response['result'] = '0'
     response['messege'] = 'response from get'
     return response

post call for login

@app.route("/login", methods=['POST'])
def postCall():
 response = {}
 response['result'] = '0'
 response['messege'] = 'response from post'
 return response

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM