Home > Software design >  Flask curl -d dont print in the console on windows
Flask curl -d dont print in the console on windows

Time:11-15

I'm starting learn Flask and i testing the http request for the console, and when i try to print a form.request on flask using the curl -d and print it on the code, the console is not printing the form request

enter image description here

(here is where is expected to print this and is not printing it

enter image description here

and heres the code

enter image description here

Like the code print it just 1 time, but when i execute the lele() again is not printing anymore

enter image description here

just when i add that line, no when i call lele()

Idk if is a windows thing, because i do this on Mac and it works, so idk

CodePudding user response:

from flask import Flask,request
app=Flask(__name__)

@app.route("/lele",methods=["GET","POST"])
def lele():
    """ You can test this in postman by selecting `form-data` in the
    `Body` and giving the `name` as key and value michael (let's say)."""
    user=request.form['name'] 
    return str(user) # this is a POST request
    # return "lele"  # this is a GET request

if __name__=="__main__":
    app.run(debug=True)
  • request.form: It is the dictionary object which contains the key-value pair of form parameters and their values.

when you run curl http://127.0.0.1:5000/lele the function should return lele and that is what is being returned. If you want to see lele as an output,then it is a GET request. If you want to see michael as an output,then it is a POST request.

  • Related