应用程序引擎Python:模板未正确呈现
我不明白呈现页面的代码有什么问题应用程序引擎Python:模板未正确呈现,python,google-app-engine,django-templates,Python,Google App Engine,Django Templates,我不明白呈现页面的代码有什么问题 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
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, {}))
借
地址栏显示http://localhost:8080/sites.htm“正确
那么代码有什么问题呢
对不起,如果我让这个问题听起来比应该的更复杂
提前谢谢 您的问题在这里是一个误解: 从名为“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”为
正确显示,但在地址栏中仍显示:
这段代码不像重定向,它只是告诉AppEngine响应POST请求,通过在
sites.htm
上呈现模板来响应登录尝试。如果您想重定向,您需要明确地执行此操作(您似乎已经尝试过)。您的问题在这里是一个误解:
从名为“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”为
正确显示,但在地址栏中仍显示:
这段代码不像重定向,它只是告诉AppEngine响应POST请求,通过在sites.htm
上呈现模板来响应登录尝试。如果您想要重定向,您需要显式地这样做(正如您似乎已经尝试过的那样)