python - Twisted:构建站点树时 putChild AttributeError

标签 python twisted

我正在尝试使用以下代码实现站点树:

root = Root()
a = root.putChild("login", login())
b = root.putChild("user", user())
c = b.putChild("register", register())

我希望它会生成这样的结构:

http://www.example.com/login
http://www.example.com/user
http://www.example.com/user/register

但是,不幸的是我收到以下错误消息:

2013-10-11 19:33:15+0300 [-] AttributeError: 'NoneType' object has no attribute 'putChild'

请帮忙。

最佳答案

user 是一个实现 twisted.web.resource.IResource 的类吗?

在这种情况下,

u = user()
root.putChild("user", u)
u.putChild("register", register())

方法 putChild 返回 None,而不是您预期的子项。

关于python - Twisted:构建站点树时 putChild AttributeError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19323759/

相关文章:

Python:删除csv文件中在某个范围内不匹配的所有行

Python Twisted 和数据库连接

python - 音频文件中的静音/暂停导致 Google 语音转文本转录提前结束

python - 从源表中获取未合并的数据

python - *_ 以及从 python 中任意长度的可迭代对象中解包元素

python - 如何修复 Twisted python 与另一端的连接以不干净的方式丢失?

python - Twisted:使用 connectProtocol 连接端点导致内存泄漏?

python - 脚本无法发出 POST 请求

python - Twisted chainDeferred, deferred.result is None

Python "range"资源消耗