Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Using mako.imports setting in Pyramid
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Hollister  
View profile  
 More options Oct 7 2012, 12:28 pm
From: Hollister <a.hollister.willi...@gmail.com>
Date: Sun, 7 Oct 2012 09:28:43 -0700 (PDT)
Local: Sun, Oct 7 2012 12:28 pm
Subject: Using mako.imports setting in Pyramid

I'd like to use  mako.imports = 'import logging' in the .ini file to replace

<%!
    import logging
%>

In each template, but it does not work. The template just throws NameError:
name 'logging' is not defined when I attempt to use it.

It appears the mako.imports doesn't even get called, since a setting like mako.imports
= 'import SpamAndEggs' doesn't throw an error.

This is probably a Pyramid issue, but I thought I'd see if anybody here.
has an idea. I'm using Pyramid 1.3 and Mako 0.7.0.

I also posted this on SO<http://stackoverflow.com/questions/12759385/pyramid-setting-mako-impo...>,
but not a peep yet.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Bayer  
View profile  
 More options Oct 7 2012, 6:34 pm
From: Michael Bayer <mike...@zzzcomputing.com>
Date: Sun, 7 Oct 2012 18:34:46 -0400
Local: Sun, Oct 7 2012 6:34 pm
Subject: Re: [Mako] Using mako.imports setting in Pyramid

i'm not sure what mako.imports is, that sounds like part of the Pyramid integration, so you'd want to check that as far as setting the config like this.

For sanity, here's how it looks in pure Mako libs:

>>> from mako.lookup import TemplateLookup
>>> l = TemplateLookup(imports=["import logging"])
>>> l.put_string("some template", "hello world")
>>> print l.get_template("some template").code

from mako import runtime, filters, cache
UNDEFINED = runtime.UNDEFINED
__M_dict_builtin = dict
__M_locals_builtin = locals
_magic_number = 8
_modified_time = 1349649241.423057
_enable_loop = True
_template_filename = None
_template_uri = 'some template'
_source_encoding = 'ascii'
import logging
_exports = []

def render_body(context,**pageargs):
    __M_caller = context.caller_stack._push_frame()
    try:
        __M_locals = __M_dict_builtin(pageargs=pageargs)
        __M_writer = context.writer()
        # SOURCE LINE 1
        __M_writer(u'hello world')
        return ''
    finally:
        context.caller_stack._pop_frame()

On Oct 7, 2012, at 12:28 PM, Hollister wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Hollister  
View profile  
 More options Oct 7 2012, 8:37 pm
From: Hollister <a.hollister.willi...@gmail.com>
Date: Sun, 7 Oct 2012 17:37:51 -0700 (PDT)
Local: Sun, Oct 7 2012 8:37 pm
Subject: Re: [Mako] Using mako.imports setting in Pyramid

Ok, so looking at the Pyramid-generated Mako template code, it just
literally outputs what's in that config setting, quotes, brackets and all.
So, the syntax has to be:

mako.imports = import logging

with multiple imports as

mako.imports = import logging, some.other.module

*not*

mako.imports = import logging, import some.other.module

Which I didn't infer from the documentation<http://pyramid.readthedocs.org/en/latest/narr/environment.html#mako-i...>that reads "String list of Python statements, typically individual “import”
lines" (but maybe I just didn't understand it correctly).

Anyway, many thanks for helping figure this one out, Mike!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Bayer  
View profile  
 More options Oct 7 2012, 9:48 pm
From: Michael Bayer <mike...@zzzcomputing.com>
Date: Sun, 7 Oct 2012 21:48:23 -0400
Local: Sun, Oct 7 2012 9:48 pm
Subject: Re: [Mako] Using mako.imports setting in Pyramid

seems like pyramid's doc is missing something.  The "string list" from the Mako pov is really a list of strings:

TemplateLookup(imports=["import logging", "import x", "import y"])

so maybe something has to happen in a pyramid config file to turn it into a list.    or maybe its just not supported.

On Oct 7, 2012, at 8:37 PM, Hollister wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Hollister  
View profile  
 More options Oct 7 2012, 10:08 pm
From: Hollister <a.hollister.willi...@gmail.com>
Date: Sun, 7 Oct 2012 19:08:56 -0700 (PDT)
Local: Sun, Oct 7 2012 10:08 pm
Subject: Re: [Mako] Using mako.imports setting in Pyramid

That's exactly what I thought. Nobody has replied from the Pyramid list yet
(pylons-discuss).


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Hollister  
View profile  
 More options Oct 8 2012, 7:42 am
From: Hollister <a.hollister.willi...@gmail.com>
Date: Mon, 8 Oct 2012 04:42:03 -0700 (PDT)
Local: Mon, Oct 8 2012 7:42 am
Subject: Re: [Mako] Using mako.imports setting in Pyramid

From pylons-discuss, the syntax is:

mako.imports =
    import logging
    import some.other.module

Import statements separated by line breaks. I think the docs should state
this with an example, as "string list" to Python people is rather different.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »