
2008年12月28日
self.response.out.write(‘【表示する文章】’)
# -*- coding: utf-8 -*-
import wsgiref.handlers
from google.appengine.ext import webapp
class MainHandler(webapp.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/html; charset=utf8'
self.response.out.write('<html><body>H2O Space.</body></html>')
def main():
application = webapp.WSGIApplication([('/', MainHandler)],
debug=True)
wsgiref.handlers.CGIHandler().run(application)
if __name__ == '__main__':
main()
画面に文字を表示するには「get」が受け取る「self」パラメータの「response.out.write」メソッドを利用します。
この時、HTMLを出力することもできますが、その場合はヘッダーを出力します。
def get(self):
self.response.headers['Content-Type'] = 'text/html; charset=utf8'
self.response.out.write('<html><body>H2O Space.</body></html>')
また、ファイルの文字コードを設定するために、ファイルの冒頭に次のようなコメントを記述します。
# -*- coding: utf-8 -*-Tweet
エイチツーオー・スペースの最新情報をメールまたはRSSでお受け取りいただけます。ぜひご利用ください。
この記事へのコメント
トラックバック