Python 配置脚本处理程序Google应用程序引擎
我正在尝试使用谷歌应用程序引擎制作一个简单的应用程序 下面是我的代码Python 配置脚本处理程序Google应用程序引擎,python,google-app-engine,python-2.5,Python,Google App Engine,Python 2.5,我正在尝试使用谷歌应用程序引擎制作一个简单的应用程序 下面是我的代码 helloworld.py print "hello" class helloworld(): def myfunc(self): st = "inside class" return st import helloworld hw_object = helloworld.helloworld() print hw_object.myfu
helloworld.py
print "hello"
class helloworld():
def myfunc(self):
st = "inside class"
return st
import helloworld
hw_object = helloworld.helloworld()
print hw_object.myfunc()
test.py
print "hello"
class helloworld():
def myfunc(self):
st = "inside class"
return st
import helloworld
hw_object = helloworld.helloworld()
print hw_object.myfunc()
app.yaml
handlers:
- url: /.*
script: helloworld.py
- url: /.*
script: test.py
handlers:
- url: /hello
script: helloworld.py
- url: /test
script: test.py
当我通过http://localhost:10000
它只打印hello
,而我的预期输出是hello
和类内
我的目录结构
E:\helloworld>dir
app.yaml helloworld.py test.py
我很确定这与此有关。那么,定义处理程序的正确方法是什么?我定义处理程序的方法有哪些错误。请浏览appengine文档中的入门指南。它将帮助您解决像这样的初始设置问题
下面是该文档中的示例处理程序
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
class MainPage(webapp.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write('Hello, webapp World!')
application = webapp.WSGIApplication(
[('/', MainPage)],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
请注意,该类扩展了webapp.RequestHandler,方法名为get(如果您正在响应http post请求,则为post)以及底部用于设置应用程序的额外代码。通过向WSGIApplication添加参数,可以向应用程序添加额外的URL。例如:
application = webapp.WSGIApplication(
[('/', MainPage)],
[('/help/', HelpPage)],
debug=True)
还请注意,在app.yaml中,由于两个脚本引用相同的url模式,因此任何请求都无法访问test.py。通常的模式是在顶部有特定的url模式,最后有一个全面的模式
祝你好运。请浏览appengine文档中的入门指南。它将帮助您解决像这样的初始设置问题
下面是该文档中的示例处理程序
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
class MainPage(webapp.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write('Hello, webapp World!')
application = webapp.WSGIApplication(
[('/', MainPage)],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
请注意,该类扩展了webapp.RequestHandler,方法名为get(如果您正在响应http post请求,则为post)以及底部用于设置应用程序的额外代码。通过向WSGIApplication添加参数,可以向应用程序添加额外的URL。例如:
application = webapp.WSGIApplication(
[('/', MainPage)],
[('/help/', HelpPage)],
debug=True)
还请注意,在app.yaml中,由于两个脚本引用相同的url模式,因此任何请求都无法访问test.py。通常的模式是在顶部有特定的url模式,最后有一个全面的模式
祝你好运。当你的第一个处理程序模式/.
匹配http://localhost:10000
,其余的处理程序都被忽略
您可以更新您的app.yaml
handlers:
- url: /.*
script: helloworld.py
- url: /.*
script: test.py
handlers:
- url: /hello
script: helloworld.py
- url: /test
script: test.py
并浏览http://localhost:10000/test
当您的第一个处理程序模式/.
匹配http://localhost:10000
,其余的处理程序都被忽略
您可以更新您的app.yaml
handlers:
- url: /.*
script: helloworld.py
- url: /.*
script: test.py
handlers:
- url: /hello
script: helloworld.py
- url: /test
script: test.py
并浏览http://localhost:10000/test
我也有类似的问题。扩展Hamish的答案,并更正方括号中的最后一部分:
application = webapp.WSGIApplication([
('/', MainPage),
('/help/', HelpPage)],
debug=True)
参考:
**编辑我在上面的代码中还有一个额外的结束括号。现在改变了。我也有类似的问题。扩展Hamish的答案,并更正方括号中的最后一部分:
application = webapp.WSGIApplication([
('/', MainPage),
('/help/', HelpPage)],
debug=True)
参考:
**编辑我在上面的代码中还有一个额外的结束括号。现在更改了。你的意思是要有两个相同的路由regexp吗?我的意思是,如果我的文件夹中有多个脚本,我如何配置我的app.yaml
。我尝试了上面的模式,但它不起作用。我需要的是,如果我运行localhost:10000
我的两个脚本都应该执行,但这不会发生。@AdamBernier:我尝试过url:/test/*
但仍然不走运。你的意思是要有两个相同的路由regexp吗?我的意思是,如果我的文件夹中有多个脚本,我如何配置我的app.yaml
。我尝试了上面的模式,但它不起作用。我需要的是如果我运行localhost:10000
我的两个脚本都应该执行,但这不是发生了。@AdamBernier:我试过url:/test/*
,但还是没有成功。