Google App Engine を独学するための基本的な Python アプリケーションを作成しようとしています。次の2つのファイルがあります。
helloworld.py:
import cgi
import webapp2
from google.appengine.api import users
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.out.write("""
<html>
<body>
<form action="/sign" method="post">
<div><textarea name="content" rows="3" cols="60"></textarea></div>
<div><input type="submit" value="Sign Guestbook"></div>
</form>
</body>
</html>""")
class Guestbook(webapp2.RequestHandler):
def post(self):
self.response.out.write('<html><body>You wrote:<pre>')
self.response.out.write(cgi.escape(self.request.get('content')))
self.response.out.write('</pre></body></html>')
app = webapp2.WSGIApplication([('/', MainPage),
('/sign', Guestbook)],
debug=True)
app.yaml
application: helloworld
version: 1
runtime: python
api_version: 1
handlers:
- url: /.*
script: helloworld.py
しかし、このアプリケーションを実行して Google Chrome で localhost:8080 にアクセスすると、予期していたフォームではなく空白のページが表示されます。なんで?ログに 200 件の応答が表示されています。
*** Running dev_appserver with the following flags:
--admin_console_server= --port=8080
Python command: /usr/bin/python2.7
/Users/davidfaux/Desktop/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/search/search.py:232: UserWarning: DocumentOperationResult._code is deprecated. Use OperationResult._code instead.
'Use OperationResult.%s instead.' % (name, name))
/Users/davidfaux/Desktop/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/search/search.py:232: UserWarning: DocumentOperationResult._CODES is deprecated. Use OperationResult._CODES instead.
'Use OperationResult.%s instead.' % (name, name))
WARNING 2012-06-21 04:30:38,064 rdbms_mysqldb.py:74] The rdbms API is not available because the MySQLdb library could not be loaded.
Warning: You are using a Python runtime (2.7) that is more recent than the production runtime environment (2.5). Your application may use features that are not available in the production environment and may not work correctly when deployed to production.
WARNING 2012-06-21 04:30:38,204 dev_appserver.py:3423] Could not initialize images API; you are likely missing the Python "PIL" module. ImportError: No module named _imaging
INFO 2012-06-21 04:30:38,220 dev_appserver_multiprocess.py:647] Running application dev~helloworld on port 8080: http://localhost:8080
INFO 2012-06-21 04:30:38,221 dev_appserver_multiprocess.py:649] Admin console is available at: http://localhost:8080/_ah/admin
INFO 2012-06-21 04:31:00,561 dev_appserver.py:2904] "GET / HTTP/1.1" 200 -
INFO 2012-06-21 04:31:00,758 dev_appserver.py:2904] "GET /favicon.ico HTTP/1.1" 200 -
INFO 2012-06-21 04:31:02,091 dev_appserver.py:2904] "GET / HTTP/1.1" 200 -
INFO 2012-06-21 04:31:02,180 dev_appserver.py:2904] "GET /favicon.ico HTTP/1.1" 200 -
INFO 2012-06-21 04:31:04,580 dev_appserver.py:2904] "GET /favicon.ico HTTP/1.1" 200