python: server is not receiving input from client flask

Chris Angelico rosuav at gmail.com
Mon Jun 28 14:40:53 EDT 2021


On Tue, Jun 29, 2021 at 4:36 AM Jerry Thefilmmaker
<jerrythefilmmaker at gmail.com> wrote:
> @app.route("/", methods = ['POST', 'GET'])
> def play():
>
> @app.route("/", methods = ['POST', 'GET'])
> def check_answer(ans, user):

When you're building a Flask app, you're defining a bunch of functions
that get called when particular requests come in. There needs to be
exactly *one* function for any given request. I would actually
recommend making the GET and POST endpoints completely separate here,
and designing them in independent functions.

One extremely helpful technique here: "If In Doubt, Print It Out".
Event-driven code can be hard to debug, so don't be afraid to make
extensive use of print() calls to examine various aspects of the
incoming request. Even just a simple thing like print("check_answer
called") can tell you all kinds of things.

HTTP is stateless by nature. You will have to think about each request
independently, and figure out how to carry the information you need.
Play around with it, have fun, and see what you can learn!

ChrisA


More information about the Python-list mailing list