python: server is not receiving input from client flask

Jerry Thefilmmaker jerrythefilmmaker at gmail.com
Mon Jun 28 15:46:07 EDT 2021


On Monday, June 28, 2021 at 2:41:23 PM UTC-4, Chris Angelico wrote:
> On Tue, Jun 29, 2021 at 4:36 AM Jerry Thefilmmaker 
> <jerrythe... 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

Do you mind elaborating a bit more on making one function for any given request?

As far as defining a bunch of functions that get called when particular requests come in I thought that's what I had going on in my codes. No? 

Also thank you, on making use of the print statement. Thought once I crossed over to the web side there was no more need for it. But what you said makes sense in terms of debugging, because sometimes I couldn't tell whether the client's variable was getting pass to my function which caused it not to be triggered.

Thank you!


More information about the Python-list mailing list