GAE/pythonでwebapp2とNDBを使おうとしています。。
データをputとしてからqueryで一覧を取得して表示しようとしています。
テストとして、フォームから送信した文字列を表示するだけのページを作ろうとしています。
以下のコードだと、ブラウザのリロードをするまでputしたデータが表示されません。
勝手な推測ですが、putが完了する前にデータの一覧を取得しているのではないかと思っています。
送信ボタンを押したら、putしたデータがすぐに表示されるようにしたいのですが
どのようにすればよいでしょうか。
python
1# -*- coding:utf-8 -*- 2import webapp2 3from google.appengine.ext import ndb 4 5class p_name(ndb.Model) 6 name = ndb.StringProperty() 7 8class MainPage(webapp2.RequestHandler): 9 def get(self): 10 query = p_name.query() 11 for i in query: 12 self.response.write('<p>%s</p>'%i.name) 13 self.response.write('<form action="/" method="post"><p><input type="text" name="p_name" size="20" /></p><p><button type="submit" name="action" value="send">送信</button></p><form>') 14 15 @ndb.transactional 16 def post(self): 17 p = p_name() 18 get_name = self.request.get('p_name') 19 p.name=get_name 20 p.put() 21 return self.redirect('/') 22 23app = webapp2.WSGIApplication([ 24 ('/',MainPage), 25], debug=True)
あなたの回答
tips
プレビュー