我试图从这个谷歌 GAE 教程视频迁移好的旧留言簿示例: http ://www.youtube.com/watch?gl=DE&hl=de&v=bfgO-LXGpTM
问题:当我通过self.redirect('/')跳转到主类时,页面不会自动重新加载。我需要手动重新加载浏览器窗口(例如通过 F5)以查看最新的留言簿条目,这是在 MakeGuestbookEntry 类中完成的。
使用 python 2.5.2 + webapp 这个问题不存在。
这是python代码文件main.py:
#!/usr/bin/env python
Import OS, says
import wsgiref.handlers
import webapp2
from google.appengine.ext import db
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext.webapp import template
class guestbook(db.Model):
message = db.StringProperty(required=True)
when = db.DateTimeProperty(auto_now_add=True)
who = db.StringProperty()
class ShowGuestbookPage(webapp2.RequestHandler):
def get(self):
# Read from the Datastore
shouts = db.GqlQuery('SELECT * FROM guestbook ORDER BY when DESC')
values = {'shouts': shouts}
self.response.out.write(template.render('main.html', values))
class MakeGuestbookEntry(webapp2.RequestHandler):
def post(self):
shout = guestbook(message=self.request.get('message'), who=self.request.get('who'))
# Write into the datastore
shout.put()
self.redirect('/')
app = webapp2.WSGIApplication([('/', ShowGuestbookPage),
('/make_entry', MakeGuestbookEntry),
debug=True)
def main():
run_wsgi_app(app)
if __name__ == "__main__":
main()
这是 html 页面 main.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Simple Guestbook with the Google App Engine</title>
</head>
<body>
<h3>Simple Guestbook with the Google App Engine</h3>
{% for shout in shouts %}
<div>
{% if shout.who %}
<b>{{shout.who}}</b>
{% else %}
<b>Anonymous</b>
{% endif %}
sagt:
<b>{{shout.message}}</b>
</div>
{% endfor %}
<p>
<form action="make_entry" method="post" accept-charset="utf-8">
Name: <input type="text" size="20" name="who" value="" if="who">
Nachricht: <input type="text" size="20" name="message" value="" if="message">
<input type="submit" value="Absenden">
</form>
</body>
</html>
谢谢你的帮助。此致