Hi I am currently trying to post to my python flask api.
In the frontend I have the following:
function onSubmit() {
fetch(environment.api + "get-selection", {
method: "POST",
header: {
"Content-Type": "application/json",
},
body: JSON.stringify(selection.value),
});
console.log(selection.value)
}
In the backend I am just trying to deal with it like this:
@routes.route("/get-selection", methods=["POST", "GET"])
def get_people():
data = request.get_json()
# data_json = data["target"]
print(format(data))
return "Hello World"
I am currently returning that string because otherwise I get the following error
When printing data
I just get None
...
I already tried request.json
and request.json()
as well as request.get_json
and nothing worked so far. For the ones asking how selection.value
looks:
I really cannot get my head around that problem and hope one of you might have an answers.
Via Active questions tagged javascript - Stack Overflow https://ift.tt/Q2rpeIL
Comments
Post a Comment