我现在正在通过 Charles Severance 的《使用 Google App Engine》一书学习 Google App Engine。
我在第 6 章,到目前为止,我已经在模板文件夹中制作了app.yaml
, index.py
,index.html
在静态文件夹中制作了 CSS 文件。
我的index.py
样子是这样的:
import os
import wsgiref.appengine.ext import webapp
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
class MainHandler(webapp.RequestHandler):
def get(self):
path=self.request.path
temp=os.path.join(os.path.dirname(__file__, 'templates' + path)
if not os.path.isfile(temp):
temp=os.path.join(os.path.dirname(__file__, 'templates/index.html')
self.response.out.write(template.render(temp,{}))
def main():
application = webapp.WSGIApplication([('/.*', MainHandler)], debug=True)
wsgiref.handlers.CGIHandler().run(application)
if __name == '__main__':
main()
为什么我会收到此错误?
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 86, in run
self.finish_response()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 127, in finish_response
self.write(data)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 202, in write
**assert type(data) is StringType,"write() argument must be string"**
AssertionError: write() argument must be string