GAE python中的YAML文件url和脚本

时间:2023-04-16
本文介绍了GAE python中的YAML文件url和脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我在 Google App Engine 中使用 Python 2.7,但似乎无法正确设置我的 app.yaml 文件.

I'm using Python 2.7 in Google App Engine and can't seem to get my app.yaml file set up right.

我的目标是,如果我去 http://localhost/carlos/ 我会得到一个已执行的 carlos.py

My goal is so that if I go to http://localhost/carlos/ I get an executed carlos.py

这是我的目录结构:

app
   app.yaml
   main.py
   carlos.py

这是我当前的 app.yaml 文件:

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

我的 carlos.py 文件是:

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)

但是我现在得到的只是 404 Not Found 错误.有什么想法吗?

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.

在我需要替换的 carlos.py 文件中:

In my carlos.py file I needed to replace:

app = webapp2.WSGIApplication([('/', MainHandler)],
                              debug=True)

app = webapp2.WSGIApplication([('/carlos/', MainHandler)],
                              debug=True)

似乎 WSGIApplication 的第一个参数是指从您的根网址开始的 TOTAL 路径,而不是最初指向它的 INCREMENTAL 路径.

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.

我选择这个答案而不是 Littm 提供的答案,因为我想继续使用 WSGI

I'm selecting this answer over what was provided by Littm because I'd like to keep using WSGI

这篇关于GAE python中的YAML文件url和脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:如何从 ruamel.yaml 转储的输出中删除 2 个空格? 下一篇:如何为 Google App Engine 应用程序编写 `app.yaml` 文件?

相关文章