简体   繁体   中英

google app engine python hello world application not displaying any thing on the localhost:8080

I ran the following hello world code in python but localhost:8080 doesnot print anything

i'm using ubuntu 12.04

localhost:8080 shows a blank page

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

output is as follows

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

You are calling write directly on the Response object. You'll want to do something like this instead:

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

There doesn't seem to be any issue with your code. The fact that GAE runs without error, and doesn't display any error in browser too makes me think that it could be a browser/display issue. Try both these things:

  • Remove the link setting the 'Content-Type', and
  • Try responding with a proper html file instead of text:

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

Well you don't really need to see the error because the execution was fine. The problem is indentation from your code. Ie import webapp2: class MainHandler(webapp2.RequestHandler): def get(self): self.response.write('Hello World') app = webapp2.WSGIApplication([('/',MainHandler)], debug=True)

Should have same indentation with class and not def

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM