问题描述
我在Google App Engine中使用Python 2.7,并且似乎无法让我的app.yaml文件设置正确。
我的目标是如果我去 http:// localhost / carlos /
我得到一个执行的carlos.py
这是我的目录结构:
app \
\app.yaml
\main.py
\ carlos.py
这是我目前的app.yaml文件:
application:myapp
版本:1
运行时:python27
api_version:1
threadsafe:yes
处理程序:
- url:/carlos/.*
脚本:carlos.app
- url:。*
script:main .app
和我的carlos.py文件是:
import webapp2
$ b $ class MainHandler(webapp2.RequestHandler):
def get(self):
self.response.out .write(Hello,Carlos!)
app = webapp2.WSGIApplication([('/ carlos',MainHandler)],
debug = True)
但是我现在得到的是一个404 Not Found错误。任何想法?
我能够确定解决方案,并认为我会将它发布给任何人。 >
在我的carlos.py文件中,我需要替换:
app = webapp2 .WSGIApplication([('/',MainHandler)],
debug = True)
与
app = webapp2.WSGIApplication([('/ carlos /',MainHandler)],
debug = True )
看起来,WSGIApplication的第一个参数是指从根网址获得的TOTAL路径而不是它最初指导的INCREMENTAL路径。
我选择了Littm提供的这个答案,因为我想继续使用WSGI
I'm using Python 2.7 in Google App Engine and can't seem to get my app.yaml file set up right.
My goal is so that if I go to http://localhost/carlos/
I get an executed carlos.py
Here is my directory structure:
app\
\app.yaml
\main.py
\carlos.py
Here is my current app.yaml file:
application: myapp
version: 1
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: /carlos/.*
script: carlos.app
- url: .*
script: main.app
and my carlos.py file is:
import webapp2
class MainHandler(webapp2.RequestHandler):
def get(self):
self.response.out.write("Hello, Carlos!")
app = webapp2.WSGIApplication([('/carlos', MainHandler)],
debug=True)
However all I'm getting now is a 404 Not Found error. Any thoughts?
I was able to determine the solution and figured I'd post it for anyone out there.
In my carlos.py file I needed to replace:
app = webapp2.WSGIApplication([('/', MainHandler)],
debug=True)
with
app = webapp2.WSGIApplication([('/carlos/', MainHandler)],
debug=True)
It appears that the first argument for the WSGIApplication is referring to the TOTAL path from your root web address as opposed to the INCREMENTAL path from which it was originally directed.
I'm selecting this answer over what was provided by Littm because I'd like to keep using WSGI
这篇关于YAML文件URL和GAE python脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!