我正在 GAE 上构建一个简单的 wiki,我想在将内容放入数据存储区时向处理程序添加一个正常的重定向。但它不起作用,直到我提交两次它重定向到内容页面而不是编辑页面本身。
Here is my handler code:
class BlogHandler(webapp2.RequestHandler):
def write(self, *a, **kw):
self.response.out.write(*a, **kw)
def render_str(self, template, **params):
params['user'] = self.user
t = jinja_env.get_template(template)
return t.render(params)
def render(self, template, **kw):
self.write(self.render_str(template, **kw))
class WikiFront(BlogHandler):
def get(self, url):
#pages = WikiData.all()
pages = db.GqlQuery("SELECT * FROM WikiData")
found = False
content = ""
for page in pages:
if page.url == url:
found = True
content = page.content
if not found:
self.redirect("/_edit" + url )
else:
self.render('wiki.html', content=content, url=url)
class EditPage(BlogHandler):
def get(self,url):
if self.user:
self.render("wiki_edit.html")
else:
self.redirect("/login")
def post(self,url):
content = self.request.get('content')
if content:
w = WikiData(parent = wiki_key(), content = content, url= url)
w.put()
self.redirect('/wiki' + url )
else:
error = "Give us content plz"
self.render("wiki_edit.html", content=content, error=error)
# mapping stuff
app = webapp2.WSGIApplication([
('wiki' + PAGE_RE, WikiFront),
('/_edit' + PAGE_RE, EditPage),
],
debug=True)