V
V
vladibuyanov2021-02-18 14:37:21
Flask
vladibuyanov, 2021-02-18 14:37:21

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()


I'm just starting out and just want to understand how to work with it.
Thank you very much for your time.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Yakushenko, 2021-02-18
@vladibuyanov

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 question

Ask a Question

731 491 924 answers to any question