繁体   English   中英

App Engine Python:模板无法正确呈现

[英]App Engine Python: Templates not rendering properly

我不明白此代码用于呈现页面可能有什么问题。

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 / sites.htm”时, “ http:// localhost:8080 / login” (“ / login”路由来自“ loginscreen.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”

那么代码有什么问题呢?

抱歉,我使这个问题听起来比应该的要复杂。

提前致谢!

您的问题在这里是一个误解:

从名为“ 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通过在sites.htm渲染模板以响应POST请求来响应该登录尝试。 如果要重定向,则需要显式地执行此操作(因为您似乎已经尝试过)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM