谷歌应用引擎python你好世界应用程序没有在localhost上显示任何东西:8080

时间:2013-10-09 12:26:41

标签: python google-app-engine

我在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

3 个答案:

答案 0 :(得分:0)

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

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

答案 1 :(得分:0)

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

  • 删除设置'Content-Type'和
  • 的链接
  • 尝试使用正确的html文件而不是文本进行响应:

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

答案 2 :(得分:0)

嗯,你真的不需要看错,因为执行得很好。 问题是代码缩进。 即 导入webapp2: class MainHandler(webapp2.RequestHandler):         def get(self):                self.response.write(&#39; Hello World&#39;) app = webapp2.WSGIApplication([(&#39; /&#39;,MainHandler)],debug = True)

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

相关问题