Pelican -- 'articles_page' is undefined
Asked Answered
D

4

8

I've created my own theme for Pelican and I've been using it for a while to build my site. I've decided to start blogging again so I'm only now adding the blog features to the site.

I've created my own blog.html template to render the content in the way I want. I started by copying and pasting the code from the 'simple' theme that comes with Pelican to get me started, but even though it is unchanged I'm getting an 'articles_page' is undefined error when I try to build.

Where is the article_page variable set from? I tried adding to my pelicanconf.py file but it didn't help.

{% 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 %}
Delia answered 15/7, 2018 at 10:23 Comment(2)
Can you also paste your flask's route here?Visigoth
I'm using Pelican, the static site generator, not Flask.Delia
S
2

You must have referenced your template from one of the articles using:

Template: blog

If you remove that reference and add the following lines to your pelicanconf.py, Pelican will generate blog.html directly from your template file:

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

(Do not forget to empty your output folder before running pelican. Tested on Pelican 3.7.1)

Scoville answered 8/10, 2018 at 21:56 Comment(1)
I did what you suggested, but it still gives me articles_page is undefinedCroon
E
1

For the sake of future visitors who might come here looking for an answer like I did:

The problem can have a good number of very diverse reasons. In my case it was not a problem with the configuration of the pelican tooling, but rather an error in the metadata of some of my content pages. I had not included the correct category, date or tag fields. You'd never guess that from the error message now, would you?

Eleazar answered 13/2, 2021 at 20:4 Comment(0)
D
1

I found this question looking for the same error.

In my case the reason was an issue which has been closed but not merged in the current release of the Attila theme. More precisely: the error is caused by a template in the templates folder of the theme which has a wrong reference inside it. In the specific case, inside the page template there was a wrong reference to article.

Changing the template manually fixed the issue:

--- a/attila-1.3/templates/page.html
+++ b/attila-1.3/templates/page.html
@@ -21,8 +21,8 @@
   {% else %}
     {% set selected_cover = SITEURL+"/"+HEADER_COVER %}
   {% endif %}
-{% elif article.color %}
-  {% set selected_color = article.color %}
+{% elif page.color %}
+  {% set selected_color = page.color %}
 {% elif HEADER_COLOR %}
   {% set selected_color = HEADER_COLOR %}
 {% endif %}

I hope this helps debugging similar errors.

Dogear answered 3/5, 2021 at 8:57 Comment(0)
H
0

The page variable articles_page is set in only one place: Writer._get_localcontext and there is a guard condition:

if paginated and template_name in self.settings['PAGINATED_TEMPLATES']:
   # ... code ...
   paginated_kwargs.update(
                        {'%s_paginator' % key: paginator,
                         '%s_page' % key: page,                    # <-- Creates `article_page`
                         '%s_previous_page' % key: previous_page,
                         '%s_next_page' % key: next_page})

If this problem crops up, the easiest solution is to make sure the guard condition evaluates to True. Most likely, the problem is that template_name is not in PAGINATED_TEMPLATES in your configuration file. I opened writers.py, added a print(f"template_name is {template_name}") and got my answer (I didn't have author : None in my PAGINATED_TEMPLATES dictionary).

Hildebrand answered 18/5, 2022 at 0:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.