Athena LivePage的页面刷新异常和解决方法

来源:互联网 发布:windows打开keynote 编辑:程序博客网 时间:2024/05/20 18:53

Athena的LivePage对象很好用,但是在刷新的时候,会有一个异常:

exceptions.AssertionError: Cannot render a LivePage more than once

 

官方说法是:

 LivePage instances maintain server-side state that corresponds to the connection to the browser. Because of this, each LivePage instance can only be used to serve a single client. When you serve LivePages?, make sure that you create a new instance for each render pass.

 

LivePage对象维护着服务端的状态,这个状态对应着从浏览器过来的连接。因此,每个LivePage对象只能用来为一个客户端服务。当你使用LivePage,一定要保证在render的时候,传回一个新对象。

 

每次使用LivePage,总要创建新实例。

 

------------------------------------July 19 更新----------------------------------

 

我们有一个Index的页面,是LivePage, 想让用户访问的第一个页面就是这个。

那在site对象建立的时候,我们就需要一个实例:

 

site = appserver.NevowSite(Index())

 

 

这样是不能刷新的,会有AssertionError错误。

 

那就这样,我们写一个RootPage, 在这个RootPage中,不论用户访问什么,总返回一个新的Index:

 

 

class RootPage(????):

'''

always return a new Index

'''

def child_(self, ctx):

return Index()

 

 

然后:

 

site = appserver.NevowSite(RootPage())

 

 

这样不就行了嘛。

 

我打"?"的地方是有问题的。

 

如果RootPage从rend.Page继承,Athena所有的js框架和自己的js文件(模板中,render "liveglue"生成)都不能被正确的加载。

要想这些js被加载,RootPage必须继承LivePage, 这样,就陷入死循环了。

 

 

具体解决的办法是:

 

class RootPage(Index):

'''

always return a new Index

'''

def child_(self, ctx):

return Index()

 

 

这样就保证不会出现刷新问题。

 

 

原创粉丝点击