[reportlab-users] Beginner's preppy puzzle: call to templatemodule.get() raises AttributeError: 'module' object has no attribute 'get'

Andy Robinson andy at reportlab.com
Mon May 13 04:16:39 EDT 2013


The 'new' version has been in the code for many years. Which function
is available depends on the first line of the .prep file.

If you declare a module with {{def(arg1, arg2 etc)}} at the top, you
can only call it with get() not getOutput() e.g.

--------------newstyle.prep------------------
{{def(name,sex)}}
<!-- This is a 'new-style' .prep file with a function-like
declaration at the top. You must call the module's get()
function, not getOutput()-->
<html>
<head>
<title>{{name}}</title>
</head>
<body>
Hello. My name is {{name}} and I am
{{if sex=="f":}} a gal
{{elif sex=="m":}} a guy
{{else:}} neuter {{endif}}
</body>
</html>
-----------------------------------------------------


-----------newstyle_go.py-------------------
def run():
from preppy import getModule
module = getModule("newstyle.prep", verbose=1)
print module.get('fred', 'm')


if __name__=='__main__':
run()
----------------------------------------------


If we explained it incorrectly in the docs, I'll try to clear it up.
Meanwhile I have just committed the above two example files into the
preppy/demo directory, so if you pull from bitbucket you can try them.

Please let us know how you get on with preppy henceforth.


- Andy


On 12 May 2013 11:36, Boar Gules <reportlab at boargules.com> wrote:

> I understand from the docs that the approved way to invoke a Preppy template

> is to use the function templatemodule.get(), but the module I am generating

> has no such function. Doing a dir() on the generated module yields

>

> ['__builtins__', '__checksum__', '__code__', '__doc__', '__file__',

> '__name__', '__package__', '__preppy__vlhs__', 'getOutput',

> 'getOutputFromKeywords', 'include', 'run']

>

> The docs say that calling getOutput() and passing in a dictionary is the old

> way to do it. I've tried that and it works.

>

> So it looks like I have downloaded an old version. The download link on

> http://www.reportlab.com/software/opensource/

> (https://bitbucket.org/rptlab/preppy) gives me version 1.0 and the PyPI

> download link

> (https://pypi.python.org/packages/source/p/preppy/preppy-1.0.1.tar.gz) gives

> me version 1.0.1. But I seem to get the same results with both.

>

> I thought I might have an old copy lurking in my Python 2.5 directory. That

> isn't it.

>

> I am clearly missing something here. Can anyone set me straight?

>

>

> _______________________________________________

> reportlab-users mailing list

> reportlab-users at lists2.reportlab.com

> http://two.pairlist.net/mailman/listinfo/reportlab-users

>




--
Andy Robinson
Managing Director
ReportLab Europe Ltd.
Thornton House, Thornton Road, Wimbledon, London SW19 4NG, UK
Tel +44-20-8405-6420


More information about the reportlab-users mailing list