I am new to database programming with Google App Engine and am programming in Python. I was wondering if I am allowed to have one Python file with several request handler classes, each of which has get and post methods. I know that the yaml file allows me to specify which scripts are run with specific urls, like the example below:
handlers:
- url: /.*
script: helloworld.py
How would I tell it to run a specific method that is in one of the classes in the .py file? Is that even possible/allowed? Do I need to separate the different request handler classes into different python files? My understanding of databases is rather shallow at the moment, so I could be making no sense.
Thanks.
Sure! That
app.yamljust transfers control tohelloworld.py, which will run themainfunction defined in that file — and that function typically sets up a WSGI app which dispatches appropriately, depending on the URL, to the right handler class. For example, look at the sample code here, very early on in the tutorial:I’m not copying the
importstatements and class definitions, because they don’t matter: this is an example of how a single.pyfile dispatches to various handler classes (two in this case).This doesn’t mean the yaml file lets you call any method whatsoever, of course: rather, it hands control to a
.pyfile, whosemainis responsible for all that follows (and e.g. with thewebappmini-framework that comes with App Engine, it will always begetorpostmethod [[orput,delete, …, etc, if you also support those — few do unless they’re being especially RESTful;-)]] being called depending on the exact HTTP method and URL in the incoming request.