atw.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:aboutthiswebsite 作者: a3n 项目源码 文件源码
def _gethumans(dbName, templateName):
    '''Return string for humans.txt.'''

    db = _dbAndClient(dbName)[0]
    metaDocs = _getMeta(db)

    # Get templateName from db.templates.
    humans = db['templates'].find_one({'name': templateName})
    if not humans:
        raise ValueError(
            '%s not found in templates collection.'%(templateName))

    ldr = jinja2.DictLoader({'humans': humans['data']})
    env = jinja2.Environment(loader=ldr)
    tmplt = env.get_template('humans')

    # Mogrify template variables into values in the rendered page.
    try:
        humanStr = tmplt.render(metaDocs)
    except Exception as e:
        # The template probably tried to get something that isn't in meta.
        # Or something.
        e.args += (', '.join([
            'Num Docs found in meta: %d'%(len(metaDocs)),
            'Names found in meta: %s'%(metaDocs.keys()),
            'Template Doc: %s'%(templateName),
            ]),)
        raise

    return humanStr
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号