Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8872293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:11:17+00:00 2026-06-14T18:11:17+00:00

I use Jinja2 compiled templates and a module loader to load the compiled templates

  • 0

I use Jinja2 compiled templates and a module loader to load the compiled templates (python code) from the datastore. But when my template contains a macro it does not work on app engine: TypeError: ‘NoneType’ object is not callable

But in the app engine SDK it works fine.
And when I skip the macro call, i receive the same error.

Without the macro it works fine. Without a solution for this macro problem, I call a python function in my template to implement the functionality of the macro.

Update: This is the template source code which results in an error:

{% extends "mainpage.html" %}
{% block form %}
    {% macro test_macro(name) %}
        <p>{{ name }}</p>
    {% endmacro %}
    <div>
    {{ test_macro('John Doe') }}
    </div>
{% endblock %}

And this is the compiled template code (the form block part):

def block_form(context, environment=environment):
    if 0: yield None
    yield u'\n'
    def macro(l_name):
        t_1 = []
        pass
        t_1.extend((
            u'\n<p>', 
            to_string(l_name), 
            u'</p>\n', 
        ))
        return concat(t_1)
    l_test_macro = Macro(environment, macro, 'test_macro', ('name',), (), False, False, False)
    yield u'\n<div>\n\t%s\n</div>\n' % (
        context.call(l_test_macro, 'John Doe'), 
    )

Update: After some debugging it worked. But I do understand it!!!
The problem: I lose my imports. And when I redefine my imports in the code. It worked.

The top of the module:

from __future__ import division
from jinja2.runtime import LoopContext, TemplateReference, Macro, Markup, TemplateRuntimeError, missing, concat, escape, markup_join, unicode_join, to_string, identity, TemplateNotFound
__jinja_template__ = None

To make it work I had to add an inline import:

from jinja2.runtime import Macro     # import again ?????     
l_test_macro = Macro(environment, macro, 'test_macro', ('name',), (), False, False, False)    

Can somebody explain, how I can lose my imports ??? I have this problem only in app engine and NOT in the SDK ??? Is this a namespace problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T18:11:18+00:00Added an answer on June 14, 2026 at 6:11 pm

    I was able to solve it, by adding the module to the sys.modules. But I do not understand why it worked in the SDK and not in GAE when I use a macro

    Here is the code of my changed module loader.

    def get_module(self, environment, template):
        # Convert the path to a module name
        name = template.replace('.html', '').replace('.txt','').replace('/', '.')   # NO extensions   
        module = None
    
        if self.package == None :                                           # load from db and not from package
            logging.info('load module : ' + name)                           # load module from runtimes db 
            if name in sys.modules : return sys.modules[name]               # already imported              
            try :
                runtime = models.Runtimes.rtimes_get_by_key_name(template)
                module_code = db.Text(runtime.compiled)                                 
                module = imp.new_module(name)
                exec module_code in module.__dict__                                         
                sys.modules[name] = module                                  # add to sys modules, so no import again
                return module
            except (ImportError, AttributeError):
                logging.error('load failed : ' + name)
    
        else : .... # load from package
    
        raise TemplateNotFound(template)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use jinja2 for my template engine in python. i would like to join
I'd like to use Jinja2 with a Django project. I'm using this template loader
I'm very new to jinja2 and the use of templates in general so I
I'am new to the Jinja2 template engine. Is there something like the view-helpers from
I don't use Python regularly, but now I have to. I should run a
I use Google app engine (python) and Jinja2 and I'd like to take advantage
I want to use jinja2.PackageLoader on Google App engine, but that appears to depend
I'm using python google app engine with the webapp framework, substituting jinja2 templates for
what sort of conditions can we use for branching in jinja2? I mean can
use Text::Table; my $tb = Text::Table->new(Planet,Radius\nkm,Density\ng/cm^3); $tb->load( [ Mercury,2360,3.7], [ Mercury,2360,3.7], [ Mercury,2360,3.7], );

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.