API和指令将对象转换为`dict`。
项目描述
rebecca.todict
rebecca.todict 是将对象转换为`dict`的API和指令。
安装
使用pip或easy_install进行安装。
$ pip install rebecca.todict $ easy_install rebecca.todict
用法
rebecca.todict提供`includeme`钩子,将`set_todict`指令设置就绪。
config.include('rebecca.todict')
使用paste deploy
pyramid.includes = rebecca.todict
通过指令注册todict适配器
通过指令
要注册todict适配器,您可以使用`set_todict`指令。
config.set_todict(Person, person_to_dict)
这会注册将Person对象转换为dict的适配器。
您还可以注册命名适配器
config.set_todict(Person, person_to_dict_short, name="short")
通过todict_decorator
todict_decorator 随机注册 todict 适配器。
@todict_config(Person) def person_to_dict(request, person): return dict(....)
使用todict API
已注册的适配器由todict API使用
from rebecca.todict import todict d = todict(request, person)
d = todict(request, person, name="short")
使用todict API的JSON渲染器
rebecca.todict.renderers.json_renderer_factory 是使用todict API的渲染器工厂。
要使用此渲染器,请注册渲染器工厂
config.add_renderer('.json', 'rebecca.todict.renderers.json_renderer_factory')
在`view_config`或`add_view`上指定“.json”渲染器
@view_config(renderer="short.json") def person_list(request): return dict(people=[Person(), Person()])
该渲染器使用名为“short”的todict适配器。
贡献者
Atsushi Odagiri,原作者
Yusuke Muraoka
变更日志
0.5 (2013-09-22)
修复使用json renderer的内容类型 #1
0.4 (2013-08-31)
修复了同名不同类型的多个todict注册冲突
0.3 (2013-08-31)
修复了多个todict注册冲突
0.2 (2013-03-02)
添加使用todict API的json渲染器
todict_config装饰器
0.1 (2013-02-16)
首次提交
项目详情
关闭
rebecca.todict-0.5.zip的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | b64323a41ba1fbed59ad95435fd93fb88053fa4d7617f8240083893158cb2b96 |
|
MD5 | 232e77d1713baee6a3a210e91f5b3e84 |
|
BLAKE2b-256 | bc068350aa76c3c31bff4f82b3443ad9060d19dbd20ece1caeefcd3f26a938c5 |
关闭
rebecca.todict-0.5-py2.py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 4ee74ee35ecd132966e9a36641250af42cba94a6db65cc25cc2b2c84be2d50cb |
|
MD5 | 36d09cae43f2deebe1a3cec81d4639b3 |
|
BLAKE2b-256 | a117700f5f77226bac4b7568a37c677275394a22d361ffda4266dc96cf8aff16 |