Answer the question
In order to leave comments, you need to log in
How to process data sent to the Flask server?
My friend and I are writing a site and he sends data from his js node server to my Flask server. I don't know how to take this data and process it. I don't even know how to approach this. My server shows that there was a Post request:
127.0.0.1 - - [18/Feb/2021 12:43:27] "?[37mPOST /api/index.php HTTP/1.1?[0m" 200 -
On the Flask server in the developer tools indicates
Status Code: 405 METHOD NOT ALLOWED
Everything I wrote the route that listens to:
from flask import Flask
app = Flask(__name__)
@app.route('/')
@app.route('/status')
def index():
return 'ok'
@app.route('/api/index.php', methods=['POST'])
def listen():
return "ok"
if __name__ == '__main__':
app.run()
Answer the question
In order to leave comments, you need to log in
All data is stored in request
.
from flask import request
@app.route('/api/index.php', methods=['POST'])
def listen():
# json данные
print(request.json)
# данные формы
print(request.form.to_dict())
# заголовки
print(dict(request.headers))
# аргументы
print(request.args)
return "ok"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question