Python Google App Engine:从 yaml 文件调用特定方法?
我是使用 Google App Engine 进行数据库编程的新手,并且正在使用 Python 进行编程。我想知道是否允许一个 Python 文件包含多个请求处理程序类,每个类都有 get 和 post 方法。我知道 yaml 文件允许我指定使用特定 url 运行哪些脚本,如下例所示:
handlers:
- url: /.*
script: helloworld.py
我如何告诉它运行 .py 文件中的类之一中的特定方法?这可能/允许吗?我是否需要将不同的请求处理程序类分离到不同的 python 文件中?目前我对数据库的了解还很浅,所以我可能没有任何意义。
谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当然!该
app.yaml
只是将控制权转移到helloworld.py
,它将运行该文件中定义的main
函数 - 并且该函数通常设置启动一个 WSGI 应用程序,该应用程序根据 URL 适当地分派到正确的处理程序类。例如,请查看此处的示例代码,非常早在教程中:我不会复制
import
语句和类定义,因为它们并不重要:这是单个.py
文件如何调度的示例到各种处理程序类(本例中为两个)。当然,这并不意味着 yaml 文件允许您调用任何方法:相反,它将控制权交给
.py
文件,该文件的main
负责所有这些事情如下(例如,对于 App Engine 附带的webapp
迷你框架,它将始终是get
或post
方法 [[或put
、delete
、...等,如果您也支持这些 — 很少有人这样做,除非它们特别 RESTful;-)]] 根据确切的 HTTP 被调用传入请求中的方法和 URL。Sure! That
app.yaml
just transfers control tohelloworld.py
, which will run themain
function 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
import
statements and class definitions, because they don't matter: this is an example of how a single.py
file 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
.py
file, whosemain
is responsible for all that follows (and e.g. with thewebapp
mini-framework that comes with App Engine, it will always beget
orpost
method [[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.