【问题标题】:My .yaml is not redirecting properly我的 .yaml 没有正确重定向
【发布时间】:2010-10-02 03:46:32
【问题描述】:

app.yaml

application: classscheduler9000
version: 1
runtime: python
api_version: 1

handlers:   
- url: /static
  static_dir: static

- url: /images
  static_dir: static/images

- url: /stylesheets
  static_dir: static/stylesheets

- url: /users\.html
  script: main.py

- url: /.*
  script: login.py

main.py

import hashlib

from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db

class AccountHolder(db.Model):
    ...

class MainPage(webapp.RequestHandler):
    def get(self):
            ...

class UserWrite(webapp.RequestHandler):
    def post(self):
        ...

application = webapp.WSGIApplication(
                                     [('/', MainPage),
                                      ('/sign', UserWrite)],
                                     debug=True)

def getMD5Hash(textToHash=None):
    return hashlib.md5(textToHash).hexdigest()

def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()

我目前正在使用 Google App Engine 进行离线测试。当我转到 localhost:8080 时,它会将我带到我的登录页面。但是,当我尝试访问 localhost:8080/users.html 时,它不会加载我的 main.py 文件(它会像断开的链接一样出错)。如果我交换 url,main.py 可以工作,但 login.py 不会加载。

我知道这可能是我的一些愚蠢的疏忽,我在谷歌或这个网站上找不到任何帮助。感谢您的帮助。

【问题讨论】:

  • 错误日志中显示什么错误?发布您的 main.py 应用程序定义。
  • 没有错误日志。一定是语义错误。

标签: python google-app-engine yaml


【解决方案1】:

问题在于您的应用程序定义。

application = webapp.WSGIApplication([('/user\.html', MainPage),
                                      ('/sign', UserWrite)],
                                     debug=True)

关于这个的文档在这里,虽然它没有“简单”的例子。 http://code.google.com/appengine/docs/python/tools/webapp/running.html

请注意,您不需要使用 .html。相反,您可以在这两个地方映射“/用户”。

【讨论】:

  • 谢谢。我非常感谢您的帮助。
猜你喜欢
  • 2020-02-10
  • 2018-04-14
  • 2021-12-06
  • 2020-05-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-08
相关资源
最近更新 更多