Mako模板:按字母顺序排列列表

时间:2016-02-01 11:42:06

标签: pyramid mako

我正在使用Python / Pyramid和Mako模板,这对我来说都很新鲜。

我有一个不同模板的列表,现在列表以随机顺序出现,但我想按字母顺序排列。 有没有人有什么建议? 以下是获取列表的代码:

<div class="panel-small">

    <h2>Choose template</h2>

    <div id="template_list">

    % if template_list and len(template_list) > 0:

        % for template in template_list:

            % if template['template']:

                <a href="#${template['type']}_${template['template_id']}" id="${template['template_id']}" class="template_link ${template['type']}">${template['name']}<br />

            % else:

                % if template['url'] is not None and template['url'].startswith('mailto'):

                    <a href="${template['url']}" class="external">${template['name']}</a><br />

                % else:

                    <a href="${template['url']}" class="external" target="_blank">${template['name']}</a><br />

                % endif

            % endif

        % endfor

    % else:

        No template.

    % endif

    </div>

</div>

1 个答案:

答案 0 :(得分:1)

只需在python中对“template_list”进行排序,然后再在模板中进行渲染。

相关问题