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

21 篇文章 0 订阅
8 篇文章 0 订阅

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()

 

 

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

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值