Ich lerne RESTFUL APIs und ich bin stecken auf ein Problem, das nur Anfrage für GET gibt aber für POST-Anfrage fehlschlägt. Der Code geht hier:Flask Python - POST funktioniert nicht wie erwartet
from flask import Flask, request
app = Flask(__name__)
#Make an app.route() decorator here
@app.route("/puppies", methods = ['GET', 'POST'])
def puppiesFunction():
if request.method == 'GET':
#Call the method to Get all of the puppies
return getAllPuppies()
elif request.method == 'POST':
#Call the method to make a new puppy
return makeANewPuppy()
def getAllPuppies():
return "Getting All the puppies!"
def makeANewPuppy():
return "Creating A New Puppy!"
if __name__ == '__main__':
app.debug = True
app.run(host='0.0.0.0', port=5000)
Die GET-Anfrage funktioniert gut, aber Fehler in POST-Anfrage. Der Fehler ist:
127.0.0.1 - - [20/May/2016 01:39:34] "POST /puppies/ HTTP/1.1" 404 -
Vielen Dank im Voraus
* Was * Fehler bekommen Sie? –
Bearbeitet. Vielen Dank. – deep
Wie machen Sie eine POST-Anfrage? 404 wird nicht gefunden Fehler. Versuchen Sie/Welpen statt/Welpen/und versuchen Sie, Methoden zu splitten, vielleicht wird es funktionieren. –