Using mako.imports setting in Pyramid

66 views
Skip to first unread message

Hollister

unread,
Oct 7, 2012, 12:32:49 PM10/7/12
to pylons-...@googlegroups.com
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.

I'm using Pyramid 1.3 and Mako 0.7.0.

I also posted this on SO, but not a peep yet.

Hollister

unread,
Oct 7, 2012, 8:42:48 PM10/7/12
to pylons-...@googlegroups.com
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 that reads "String list of Python statements, typically individual “import” lines" (but maybe I just didn't understand it correctly).

Thanks to Mike Bayer for pointing me in the right direction in replying to my post on Mako. https://groups.google.com/forum/#!topic/mako-discuss/RNUfqX12YHE

Michael Merickel

unread,
Oct 7, 2012, 11:28:29 PM10/7/12
to pylons-...@googlegroups.com
"individual import lines" is indicating support for something like

mako.imports =
import logging
import some.other.module
> --
> You received this message because you are subscribed to the Google Groups
> "pylons-discuss" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/pylons-discuss/-/8AbXxhbNCTsJ.
>
> To post to this group, send email to pylons-...@googlegroups.com.
> To unsubscribe from this group, send email to
> pylons-discus...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/pylons-discuss?hl=en.

Hollister

unread,
Oct 8, 2012, 7:39:06 AM10/8/12
to pylons-...@googlegroups.com
Ah, so not a string list in the Python sense at all.
This is where a brief example would go a long way.

Thanks!
Reply all
Reply to author
Forward
0 new messages