掲示板をつくってみた。
管理者側で入力した内容が、5秒ごとにユーザ画面に転送されます。
さすがに、メタリフレッシュはかっこ悪いので、AJAXなどで書き換えるように変更しないとなー。
ソースコード
ソースコードは以下の通り。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #!/usr/bin/env python from google.appengine.ext import webapp, db from google.appengine.ext.webapp import util class MainHandler(webapp.RequestHandler): def get(self): board = SharedBoard.all().get() self.response.out.write(board.contents) self.response.out.write("""<meta http-equiv="Refresh" content="5;URL=/" />""") class AdminHandler(webapp.RequestHandler): def get(self): board = SharedBoard.all().get() if board == None: contents = "" else: contents = board.contents self.response.out.write("""<form method="post" action="/admin"><input type="hidden" name="phpMyAdmin" value="cfc2644bd9c947213a0141747c2608b0" /> <div><textarea style="height:100px;width:400px;" name="contents">%s</textarea></div> <div><input type="submit" value="save"></div> </form>""" % contents) def post(self): board = SharedBoard.all().get() if board == None: board = SharedBoard() board.contents = self.request.get('contents') board.put() self.redirect('/admin') def main(): application = webapp.WSGIApplication([('/', MainHandler),('/admin', AdminHandler)], debug=True) util.run_wsgi_app(application) class SharedBoard(db.Model): contents = db.TextProperty() if __name__ == '__main__': main() |