python – Pelican – ‘articles_page’未定义

我为Pelican创建了自己的主题,并且我已经使用它一段时间来构建我的网站.我决定再次开始写博客,所以我现在才将博客功能添加到网站上.

我已经创建了自己的blog.html模板,以我想要的方式呈现内容.我开始通过复制和粘贴Pelican附带的“简单”主题中的代码来启动我,但即使它没有改变,当我尝试构建时,我得到’articles_page’是未定义的错误.

article_page变量在哪里设置?我尝试添加到我的pelicanconf.py文件,但它没有帮助.

{% extends 'base.html' %}
{% block title %}{{ page.title }} — Ricky White{% endblock title %}

{% block content %}  

<section class="wrapper">
<div class="container">
    <div class="row">
        <div class="col">
            <ol id="post-list">
                {% for article in articles_page.object_list %}
                    <li><article class="hentry">
                            <header> <h2 class="entry-title"><a href="{{ SITEURL }}/{{ article.url }}" rel="bookmark" title="Permalink to {{ article.title|striptags }}">{{ article.title }}</a></h2> </header>
                            <footer class="post-info">
                                <time class="published" datetime="{{ article.date.isoformat() }}"> {{ article.locale_date }} </time>
                                <address class="vcard author">By
                                {% for author in article.authors %}
                                    <a class="url fn" href="{{ SITEURL }}/{{ author.url }}">{{ author }}</a>
                                {% endfor %}
                                </address>
                            </footer><!-- /.post-info -->
                            <div class="entry-content"> {{ article.summary }} </div><!-- /.entry-content -->
                    </article></li>
                {% endfor %}
            </ol><!-- /#posts-list -->
            {% if articles_page.has_other_pages() %}
                {% include 'pagination.html' %}
            {% endif %}

        </div>
    </div>
</div>
</section>
{% endblock content %}

最佳答案 您必须使用以下文章之一引用您的模板:

Template: blog

如果删除该引用并将以下行添加到pelicanconf.py,Pelican将直接从您的模板文件生成blog.html:

DIRECT_TEMPLATES = ['index', 'blog']
PAGINATED_DIRECT_TEMPLATES = ['blog']

(在运行pelican之前不要忘记清空输出文件夹.在Pelican 3.7.1上测试)

点赞