【发布时间】:2012-03-23 10:07:35
【问题描述】:
我不明白这段渲染页面的代码有什么问题。
def post(self):
acct = self.request.get('account')
pw = self.request.get('password')
que = db.Query(User)
que = que.filter('account =', acct)
que = que.filter('password =', pw)
results = que.fetch(limit = 1)
values = { }
newval = dict(values)
newval['path'] = self.request.path
if len(results) > 0:
path = os.path.join(os.path.dirname(__file__), 'templates/sites.htm')
self.response.out.write(template.render(path, {}))
我从一个名为 "loginscreen.htm" 的页面上的登录表单调用它。 当应用程序到达这部分代码时:
if len(results) > 0:
path = os.path.join(os.path.dirname(__file__), 'templates/sites.htm')
self.response.out.write(template.render(path, {}))
并尝试重定向到 'sites.htm',页面 'sites.htm' 正确显示,但在地址栏中仍显示:
'http://localhost:8080/login'(“/login”路由来自“loginscreen.htm”的传入请求)当'http://localhost:8080/sites .htm' 应该 改为显示。
这样做的主要问题是,如果我重新加载页面,“确认表单重新提交” 对话框会出现,允许用户再次提交表单。 但是如果我替换
path = os.path.join(os.path.dirname(__file__), 'templates/sites.htm')
self.response.out.write(template.render(path, {}))
由
self.redirect('sites.htm')
地址栏正确显示'http://localhost:8080/sites.htm'。
那么代码有什么问题呢?
对不起,如果我让这个问题听起来比应该的更复杂。
提前致谢!
【问题讨论】:
标签: python google-app-engine django-templates