【问题标题】:google app engine python hello world application not displaying any thing on the localhost:8080谷歌应用引擎 python hello world 应用程序未在 localhost:8080 上显示任何内容
【发布时间】:2013-10-09 12:26:41
【问题描述】:

我在 python 中运行了以下 hello world 代码,但 localhost:8080 不打印任何内容

我使用的是 ubuntu 12.04

localhost:8080 显示空白页

helloworld.py

import webapp2


class MainPage(webapp2.RequestHandler):

def get(self):
    self.response.headers['Content-Type'] = 'text/plain'
    self.response.write('Hello, World!')


application = webapp2.WSGIApplication([
('/', MainPage),
], debug=True)

app.yaml

application: your-app-id
version: 1
runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /.*
  script: helloworld.application

输出如下

kiran@kiru-Lenovo-G480:~/google$ dev_appserver.py helloworld/
INFO     2013-10-09 12:22:03,559 sdk_update_checker.py:245] Checking for updates to the SDK.
INFO     2013-10-09 12:22:03,565 __init__.py:94] Connecting through tunnel to: appengine.google.com:443
INFO     2013-10-09 12:22:03,571 sdk_update_checker.py:261] Update check failed: <urlopen error Tunnel connection failed: 407 Proxy Authentication Required>
INFO     2013-10-09 12:22:03,595 api_server.py:138] Starting API server at: http://localhost:44748
INFO     2013-10-09 12:22:03,610 dispatcher.py:168] Starting module "default" running at: http://localhost:8080
INFO     2013-10-09 12:22:03,614 admin_server.py:117] Starting admin server at: http://localhost:8000

【问题讨论】:

  • def get 的缩进似乎是错误的 - 它应该在类内缩进。但这可能是复制代码的结果。

标签: python google-app-engine


【解决方案1】:

您直接在Response 对象上调用write。你会想做这样的事情:

self.response.out.write('Hello, World!')

【讨论】:

    【解决方案2】:

    您的代码似乎没有任何问题。 GAE 运行没有错误,并且在浏览器中也没有显示任何错误的事实让我认为这可能是浏览器/显示问题。试试这两件事:

    • 删除设置“Content-Type”的链接,然后
    • 尝试使用正确的 html 文件而不是文本来响应:

      self.response.write(template.render(tvalues))

    【讨论】:

      【解决方案3】:

      好吧,您实际上并不需要查看错误,因为执行很好。 问题是您的代码缩进。 IE 导入 webapp2: 类 MainHandler(webapp2.RequestHandler): 定义获取(自我): self.response.write('Hello World') app = webapp2.WSGIApplication([('/',MainHandler)], debug=True)

      应该与类而不是def具有相同的缩进

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-01-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-07-13
        • 1970-01-01
        相关资源
        最近更新 更多