from pyramid.path import AssetResolver
a = AssetResolver()
resolver = a.resolve('myproject:templates/foo.pt')
print(resolver.abspath())
# -> /path/to/myproject/templates/foo.pt
具体来说,它对解析路径有这样的描述:
If spec is an absolute filename (e.g. /path/to/myproject/templates/foo.pt) or an absolute asset spec (e.g. myproject:templates/foo.pt), an asset descriptor is returned without taking into account the package passed to this class' constructor.
要从点式资产规范出发,您可以使用
pyramid.path.AssetResolver
,正如documentation所述,如下所示:具体来说,它对解析路径有这样的描述:
但是我强烈建议不要让用户直接修改包中的模板文件。相反,我建议您在安装过程中使用一种方法,将所有模板从包中复制出来,然后使用Pyramids asset override机制将现有的资产规范分包到新的位置。此时,您可以使用标准的Python打开/关闭文件方法让用户更新模板。在
相关问题 更多 >
编程相关推荐