简体   繁体   中英

Can Flask post internally in python?

Is it possible to make an internal post in flask? I'm trying to figure out how to post to an external site inside of python. Lets say I have a simple method like:

    @app.route("/<test_value>", methods=["GET","POST"])  
        def test_post(test_value):
            ?post?(test_value, url)
            return redirect("/")

Is there method I could use to make that post or would I be best off using javascript?

The requests library is the most popular one, here is a sample code on how to send a post with some data.

>>> payload = {'key1': 'value1', 'key2': 'value2'}
>>> r = requests.post("http://httpbin.org/post", data=payload)
>>> print(r.text)
{
  ...
  "form": {
    "key2": "value2",
    "key1": "value1"
  },
  ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM