[Python] How to make a simple POST function with flask?

Discussão em 'Python' iniciado por Stack, Setembro 27, 2024.

  1. Stack

    Stack Membro Participativo

    I made a local service to learn flask and trying to write some get/post functions. I have no problem with GET but POST just confused me a bit. What I want to do is when some user send his name as POST request service will return as "Hello name". I made some research but everything I saw was so complicated and full of json. I do not want to use json because I just send a string and return a string. Can you guys just help me with that and tell me how can I test that post request on curl? Thanks in advance!

    Edit: I tried to write my data in json format as

    data = { "name" : " "}


    and tried to post like

    @app.route("/f",methods=['POST'])
    def f():
    request_data = request.get_json()
    myName = request_data['name']
    return (str(myName))


    but did not work.

    Continue reading...

Compartilhe esta Página