绝对初学者问题:Google App Engine:如何将值传递给我的请求处理程序?
我有一个模板index.html文件看起来像这样:
...
<FRAMESET ROWS="10%, *">
<FRAME SRC="/top_frame">
<FRAME SRC="{{ bottom_frame_url }}">
</FRAMESET>
...
和赞成/ top_frame请求处理程序,看起来像这样:
class TopFrame(webapp.RequestHandler):
def get(self):
...
bottom_frame_url = self.request.get('bottom_frame_url')
...
由于你可以看到,我想拥有的价值{{bottom_frame_url}}这是用来生成我的index.html,但如何我这个值传递给我的TopFrame请求处理?
谢谢!
编辑:
class MainPage(webapp.RequestHandler):
def get(self):
...
bottom_frame_url = Site.qql("WHERE Category = :1 ORDER BY date DESC",category_name)
...
args = {
...
'bottom_frame_url': bottom_frame_url,
...
}
index_path = os.path.join(os.path.dirname(__file__), 'index.html')
self.response.out.write(template.render(index_path, args))
但是,当我们在index.html的模板遭遇 “/ top_frame” 我TopFrame请求处理程序被称为:我从另一个请求处理程序渲染的index.html
class TopFrame(webapp.RequestHandler):
def get(self):
...
bottom_frame_url = self.request.get('bottom_frame_url')
...
args = {
'bottom_frame_url': bottom_frame_url
}
self.response.out.write(template.render('topframe.html', args))
但self.request.get(“bottom_frame_url”)似乎并没有被读取任何价值。我知道价值已经在我的index.html模板设置,因为当我渲染页面的底部框架显示为我设置的网站,但顶部框架显示在下面的错误结束了回溯:
NameError: global name 'bottom_frame_url' is not defined
它貌似我不得不把更多的代码在我的index.html模板bottom_frame_url的价值明确地传递给我的TopFrame请求处理。它是否正确?
我能想到的另一件事是,虽然我传递bottom_frame_url作为参数来呈现的index.html,当我尝试呈现topframe.html这种说法尚未公布,因为我还没有呈现底部框架呢。情况会是这样吗?