这里是新手——我一直在尝试使用谷歌应用程序引擎在 Bottle 中创建一个“Hello World”。我显示了“hello world”部分,但即使在索引页面上,我也得到以下输出:“Hello world!状态: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')
最佳答案
这是关于 GAE 上的 Bottle 的一个很好的教程: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
正如您所看到的,与示例代码有许多差异。本教程很好地解释了它们,因此我在这里不再赘述。
关于python - 使用谷歌应用程序引擎部署 Bottle 应用程序时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12662972/