【问题标题】:How to open a txt file in a mako template?如何在mako模板中打开txt文件?
【发布时间】:2015-06-29 19:38:13
【问题描述】:

我的 tree.txt 文件存储在目录树中。我想在 mako 模板中打开它,并获取它的上下文。
示例(应该有效 - 但无效):

% for i in open("tree.txt", "r").read():
    i   
% endfor 

【问题讨论】:

  • 什么不起作用?你有什么错误吗?
  • 这个错误:IOError: [Errno 2] No such file or directory: 'tree.txt'
  • 简单 catdgory 中的“tree.txt”和 mako 模板文件

标签: python mako


【解决方案1】:

% for i in open("/xxx/xxxx/xxxxxx/xxxxxx/tree.txt", "r").read():

${i}

% 结束

已经解决了。使用mako模板打开文件时,必须使用绝对路径。

【讨论】:

    猜你喜欢
    • 2016-08-02
    • 2020-12-04
    • 2014-03-07
    • 1970-01-01
    • 2011-04-01
    • 2019-12-13
    • 2017-05-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多