There is a need to make POST request from server side in Flask.
Let’s imagine that we have:
@app.route("/test", methods=["POST"])
def test():
test = request.form["test"]
return "TEST: %s" % test
@app.route("/index")
def index():
# Is there something_like_this method in Flask to perform the POST request?
return something_like_this("/test", { "test" : "My Test Data" })
I haven’t found anything specific in Flask documentation. Some say urllib2.urlopen is the issue but I failed to combine Flask and urlopen. Is it really possible?
Yes, to make a POST request you can use
urllib, see the documentation.I would however recommend to use the requests module instead.
EDIT:
I suggest you refactor your code to extract the common functionality: