AttributeError: 'Undefined' object has no attribute 'meta'

11 views
Skip to first unread message

Julien Vallet

unread,
May 13, 2020, 4:59:50 AM5/13/20
to nikola-discuss

Hi,


I have trouble with the replacement of an old theme.

When building under a new theme (canterville), I get a


__M_writer(str(post.meta('banner')))
AttributeError: 'Undefined' object has no attribute 'meta'

########################################
render_galleries:output/galleries/index.html <stdout>:
 

Maybe its because I misused conf.py ?


GLOBAL_CONTEXT = {
   "BANNER_URL": '/assets/img/oeil.jpg',

}


Yet I've been careful with the Global_context location...


Or in my template ?


<div class="site-wrapper">
    % if 'main_index' in pagekind:
    <header class="main-header" style="background-image: url(${BANNER_URL})">
    % else:
    <header class="main-header" style="background-image: url(${post.meta('banner')})">
    % else:
    <header class="main-header post-head no-cover">
    % endif
 

Can you help me ?

Roberto Alsina

unread,
May 13, 2020, 5:02:44 AM5/13/20
to Nikola—Discuss
You probably need to check if the page you are rendering has a post or not. What template is this?

--
You received this message because you are subscribed to the Google Groups "nikola-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nikola-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nikola-discuss/18d436ab-0fe6-45d2-bfdf-f47768b6a729%40googlegroups.com.

Julien Vallet

unread,
May 13, 2020, 5:12:48 AM5/13/20
to nikola-discuss
It has three posts and it's the index template.

Roberto Alsina

unread,
May 13, 2020, 5:16:58 AM5/13/20
to Nikola—Discuss
Ok, the index template has no post, so you will need to make that conditional on post being there.

--
You received this message because you are subscribed to the Google Groups "nikola-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nikola-discus...@googlegroups.com.

Julien Vallet

unread,
May 13, 2020, 5:22:49 AM5/13/20
to nikola-discuss
Sorry but what does it mean ?

Julien Vallet

unread,
May 13, 2020, 5:29:23 AM5/13/20
to nikola-discuss
Sorry, my english is too bad. How can I do that ?

Julien Vallet

unread,
May 13, 2020, 5:49:01 AM5/13/20
to nikola-discuss
Yet there is a block for articles no ?

<div class="postindex">
% for post in posts:


<article class="post post">
   
<header class="post-header">
       
<h2 class="post-title"><a href="${post.permalink()}">${post.title()|h}</a></h2>
   
</header>
    %if index_teasers:
   
<section class="post-excerpt">
    ${post.text(teaser_only=True)}
    %else:
   
<section class="post-excerpt">
    ${post.text(teaser_only=False)}
    %endif
   
</section>
   
<footer class="post-meta">
            % if author_pages_generated:
               
<a href="${_link('author', post.author())}">${post.author()|h}</a>
            % else:
                ${post.author()|h}
            % endif

        on
            % for tag in post.tags:
               
<a href="link://tag/${tag}">#${tag}</a>,
            % endfor

       
<time class="post-date" datetime="${post.formatted_date('webiso')}">
            ${post.formatted_date(date_format)|h}
       
</time>
   
</footer>
</article>



Roberto Alsina

unread,
May 13, 2020, 6:08:20 AM5/13/20
to Nikola—Discuss
The template has no "post", you only have it inside that loop, after the line

% for post in posts:

I am guessing the call to post.meta that's failing is outside that.
Trying to explain how to fix that without context is difficult, but you just can't use post anywhere outside that loop.


--
You received this message because you are subscribed to the Google Groups "nikola-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nikola-discus...@googlegroups.com.

Julien Vallet

unread,
May 13, 2020, 6:30:06 AM5/13/20
to nikola-discuss
Can I send you the context ? What would you need ? I'm just at the end of the rope
To unsubscribe from this group and stop receiving emails from it, send an email to nikola-...@googlegroups.com.

Roberto Alsina

unread,
May 13, 2020, 7:08:20 AM5/13/20
to Nikola—Discuss
On Wed, May 13, 2020 at 7:30 AM Julien Vallet <j.su...@wanadoo.fr> wrote:
Can I send you the context ? What would you need ? I'm just at the end of the rope


Is your site's source code somewhere I can see it?

Or just make a zip and email it to me.

Roberto Alsina

unread,
May 21, 2020, 5:14:57 AM5/21/20
to Nikola—Discuss
I got the zip you sent me.

* I moved aside the copy of canterville you included and downloaded the original
* Re-added as empty the galleries you removed before sending

And it built just fine.

* Put back your version of canterville:

[2020-05-21 06:12:17] ERROR: Nikola: File "/home/ralsina/Downloads/x/nikola_test/cache/.mako.tmp/base.tmpl.py", line 88
    else:
    ^
SyntaxError: invalid syntax

So, the problem seems to either have been fixed in canterville after you installed it, or was introduced when you edited it.

These are the relevant differences:

-    % if 'main_index' in pagekind and BANNER_URL:
+    % if 'main_index' in pagekind and BANNER_URL :

     <header class="main-header" style="background-image: url(${BANNER_URL})">
-    % else:
+    % elif 'post_page' in pagekind and post.meta('banner'):

     <header class="main-header" style="background-image: url(${post.meta('banner')})">
     % else:
     <header class="main-header post-head no-cover">

You can just get the original base.tmpl from canterville and replace yours and it will probably build just fine:


Julien Vallet

unread,
May 22, 2020, 4:25:58 AM5/22/20
to nikola-discuss
It worked just fine thanks ! I had changed the base.tmpl trying to impose the banner.
Now the site works well, but I'm still in struggle with the metadata, yet I think I have set the global context at the right place and tried numerous possibilities to set the pagekind to main_index and BANNER_URL.
Did the banner opened when you build it ?



Le mercredi 13 mai 2020 10:59:50 UTC+2, Julien Vallet a écrit :

Roberto Alsina

unread,
May 22, 2020, 4:31:08 AM5/22/20
to Nikola—Discuss
I did not check anything other than that it built.

--
You received this message because you are subscribed to the Google Groups "nikola-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nikola-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nikola-discuss/30d378ed-0a7d-4752-ba9c-b9f1cafefdb4%40googlegroups.com.

Julien Vallet

unread,
May 22, 2020, 4:36:20 AM5/22/20
to nikola-discuss
Yet my output does not compile it, there is just the logo and the menu, and the header is "post-head no-cover".

Le mercredi 13 mai 2020 10:59:50 UTC+2, Julien Vallet a écrit :

moi

unread,
May 22, 2020, 7:19:29 AM5/22/20
to nikola-...@googlegroups.com
Thanks ! It works just fine. But did the banner appears to you ? 
I modified the global context in the conf.py but it doesn't seem to work for me. 
I surely checked the google discuss about the same problem... 

--
You received this message because you are subscribed to the Google Groups "nikola-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nikola-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nikola-discuss/CALXDAfr94HgQKHVQPF%3D4SZGutGX0mirJ-jyYyM6L81K1Eka_%3Dg%40mail.gmail.com.

Reply all
Reply to author
Forward
0 new messages