配置脚本处理程序 Google App Engine
我正在尝试使用 Google App Engine 制作一个简单的应用程序。
下面是我的代码
helloworld.py
print "hello"
class helloworld():
def myfunc(self):
st = "inside class"
return st
test.py
import helloworld
hw_object = helloworld.helloworld()
print hw_object.myfunc()
app.yaml
handlers:
- url: /.*
script: helloworld.py
- url: /.*
script: test.py
当我通过 http://localhost:10000 运行我的应用程序时
它只打印 hello
而我的预期输出是 hello
和 inside class
。
我的目录结构
E:\helloworld>dir
app.yaml helloworld.py test.py
我很确定这与脚本处理程序有关。那么,定义处理程序的正确方法是什么以及我定义它们的方法有什么问题。
I am trying to make a simple application using Google App Engine.
Below is my code
helloworld.py
print "hello"
class helloworld():
def myfunc(self):
st = "inside class"
return st
test.py
import helloworld
hw_object = helloworld.helloworld()
print hw_object.myfunc()
app.yaml
handlers:
- url: /.*
script: helloworld.py
- url: /.*
script: test.py
When I run my application via http://localhost:10000
it prints only hello
whereas my expected output is hello
and inside class
.
My directory structure
E:\helloworld>dir
app.yaml helloworld.py test.py
I am pretty sure this has something to do with Script Handlers.So, what is the correct way to define handlers and what is wrong in my way of defining them.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当您的第一个处理程序模式
/.*
与http://localhost:10000
匹配时,其余处理程序将全部被忽略。您可以更新您的
app.yaml
并浏览
http://localhost:10000/test
When your first handler pattern
/.*
matcheshttp://localhost:10000
, the remaining handlers are all ignored.You can updated your
app.yaml
And browse
http://localhost:10000/test
请浏览 appengine 文档中的入门指南。它将帮助您解决此类初始设置问题。
http://code.google.com/appengine/docs/python/gettingstarted /helloworld.html
这是该文档中的示例处理程序。
请注意,该类扩展了 webapp.RequestHandler,方法名称为 get(如果您响应 http post 请求,则为 post),还有底部用于设置应用程序的额外代码。您可以通过向 WSGIApplication 添加参数来向应用程序添加额外的 URL。例如:
另请注意,在您的 app.yaml 中,由于两个脚本都引用相同的 url 模式,因此任何请求都无法到达 test.py。正常的模式是在顶部有特定的 url 模式,最后是一个包罗万象的模式。
祝你好运。
Please walk through the Getting Started guide from the appengine documentation. It will help you get through the initial setup problems like this.
http://code.google.com/appengine/docs/python/gettingstarted/helloworld.html
Here is the sample Handler from that documentation.
Note that the class extends webapp.RequestHandler, the method name is get (or post if you are responding to a http post request) Also the extra code at the bottom for setting up the application. You can add extra URL's to the application by adding arguments to the WSGIApplication. For example:
Also note that in your app.yaml as both scripts refer to the same url pattern, there is no way that any request will ever get to test.py. The normal pattern is to have specific url patterns at the top and a catch-all patter last.
Good Luck.
我也有类似的问题。扩展哈米什的答案,并纠正方括号的最后部分:
参考:
https://webapp-improved.appspot.com/guide/routing.html
** 编辑我上面的代码中还有一个额外的右括号。现在改变了。
I had a similar problem too. Expanding on Hamish's answer, and correcting the last part where the square brackets are:
Reference:
https://webapp-improved.appspot.com/guide/routing.html
** Edit I also had an extra closing bracket in my code above. Changed that now.