Google app engine 无法在google app engine中找出yaml和主页处理程序之间的关系
我在google和stackoverflow中进行了大量搜索,但无法找出我的代码为什么不起作用 app.yaml文件如下:Google app engine 无法在google app engine中找出yaml和主页处理程序之间的关系,google-app-engine,yaml,Google App Engine,Yaml,我在google和stackoverflow中进行了大量搜索,但无法找出我的代码为什么不起作用 app.yaml文件如下: application: morgan629200774 version: 1 runtime: python27 api_version: 1 threadsafe: yes handlers: - url: /.* script: main.app - url: /unit1/ script: unit1.app - url: /unit2/ scr
application: morgan629200774
version: 1
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: /.*
script: main.app
- url: /unit1/
script: unit1.app
- url: /unit2/
script: unit2.app
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
libraries:
- name: webapp2
version: "2.5.2"
这是我的代码:
import webapp2
form = """
<form method="post">
Enter some text to ROT13
<br>
<br>
<div><textarea name="content" rows="7" cols="50"></textarea></div>
<input type="submit" value="submit">
<br>
<br>
</form>
"""
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.out.write("main page")
class unit1(webapp2.RequestHandler):
def get(self):
self.response.out.write("hello world")
class unit2(webapp2.RequestHandler):
def get(self):
self.response.out.write(form)
self.response.out.write("hello world")
def post(self):
rot13=''
text=self.request.get('content')
rot13=text.encode('rot13')
self.response.out.write(rot13)
app = webapp2.WSGIApplication([
('/.*', MainPage),
('/unit1/', unit1),
('/unit2/', unit2)
], debug=True)
导入webapp2
form=”“”
输入一些文本以进行旋转13
"""
类主页(webapp2.RequestHandler):
def get(自我):
self.response.out.write(“主页”)
类unit1(webapp2.RequestHandler):
def get(自我):
self.response.out.write(“你好,世界”)
类unit2(webapp2.RequestHandler):
def get(自我):
自我.回应.输出.写入(表格)
self.response.out.write(“你好,世界”)
def post(自我):
rot13=''
text=self.request.get('content')
rot13=text.encode('rot13')
自我。回应。输出。写入(rot13)
app=webapp2.WSGIApplication([
(“/.*”,主页),
(“/unit1/”,unit1),
(“/unit2/”,unit2)
],debug=True)
有人能告诉我我做错了什么吗
谢谢你没有(也不需要)一个unit1.app
或unit2.app
,所以我不知道你为什么在app.yaml中引用它们。从Python代码中可以看到,有一个对象名为app
,它包含整个应用程序的路由。我假定(尽管您没有声明)Python文件名为“main.py”。这就是app.yaml引用main.app
-即main
模块中的app
对象的原因
app.yaml中URL的用途只是将其传递给Python代码。因此,您只需要一个处理程序:第一个。删除另外两个处理程序。它捕获/
下的所有内容并将其传递到main.app。在该文件中,底部定义的第一条管线应为:
('/', MainPage)
因为您不想捕获该路由中的所有内容,只想捕获特定的根URL。谢谢!好的,我从yaml文件中删除了app1和app2,但是现在当我尝试在localhost:port/unit1或localhost:port/unit2中运行代码时,出现了404错误