使用谷歌应用引擎部署瓶子应用程序的问题

时间:2012-09-30 16:38:05

标签: python google-app-engine bottle

新手在这里 - 我一直试图用谷歌应用引擎在瓶子里创建一个“Hello World”。我得到了“hello world”部分,但即使在索引页面上,我也得到以下输出:“Hello world!Status:500”
如果我尝试添加新路由(例如'/ page'路由),并导航到新路由,我会收到“服务器错误:网站在检索时遇到错误...可能因维护失败或配置错误“。导航到未正确配置的页面后,如果我尝试返回“/”,我也会收到服务器错误。我已将bottle.py放在我的根目录中。有人可以帮我配置正确的文件吗?谢谢!

import bottle 
from bottle import route, template, request, error, debug

@route('/')
def index():
    return "Hello World!"

@route('/page')
def page():
    return 'page!'

bottle.debug(True)
bottle.run(server='gae')

3 个答案:

答案 0 :(得分:2)

以下是关于GAE瓶子的好教程:http://blog.rutwick.com/use-bottle-python-framework-with-google-app-engine

免责声明:我没有运行教程,但它看起来是正确的。

main.py:

from framework import bottle
from framework.bottle import route, template, request, error, debug
from google.appengine.ext.webapp.util import run_wsgi_app

@route('/')
def DisplayForm():
    message = 'Hello World'
    output = template('templates/home', data = message)
    return output

def main():
    debug(True)
    run_wsgi_app(bottle.default_app())

@error(403)
def Error403(code):
    return 'Get your codes right dude, you caused some error!'

@error(404)
def Error404(code):
    return 'Stop cowboy, what are you trying to find?'

if __name__=="__main__":
    main()

的app.yaml:

application: my-bottle-app
version: 1
runtime: python
api_version: 1

handlers:
- url: /styles
  static_dir: styles

- url: /.*
  script: main.py

如您所见,与示例代码存在许多差异。本教程很好地解释了它们,所以我不会在这里详细介绍。

答案 1 :(得分:2)

这可能会有所帮助:

的app.yaml:

application: my-app
version: 1
runtime: python27
api_version: 1
threadsafe: yes

- url: .*
  script: main.app

main.py:

import bottle

@bottle.route('/')
def root():
    return 'hello!'

bottle.run(server='gae', debug=True)
app = bottle.app()

以下是GitHub的原始答案。 https://github.com/defnull/bottle/issues/401

答案 2 :(得分:0)

App Engine + Bottle started code中使用类似WSGI时,您可以在代码在开发服务器上运行时调用bottle.debug()

import bottle
import os

DEBUG = os.environ.get('SERVER_SOFTWARE','').startswith('Development')  
bottle.debug(DEBUG)
app = bottle.Bottle()

app.yaml

handlers:
- url: .*
  script: main.app