我正在通过Google的App Engine留言本示例(可在此处找到:https://cloud.google.com/appengine/docs/standard/python/getting-started/creating-guestbook)
我正在尝试将输出(Greetings)重定向到另一个页面,而不是index.html,当用户按下“Sign the Guestbook”按钮后,它们当前显示在那里。我创建了一个名为greetings.html的单独页面,我在其中复制了index.html页面中的显示代码。但是,我不知道如何修改guestbook.py以使输出转到新页面。
答案 0 :(得分:1)
webapp2有一个内置的redirect
方法:
return redirect('/some-path')
但是,我认为您可能宁愿将收集到的数据发送到greetings.html
模板?在POST
方法下,您可以执行以下操作:
template_values = {
'guestbook_name': guestbook_name,
# etc.,
}
template = JINJA_ENVIRONMENT.get_template('greetings.html')
self.response.write(template.render(template_values))