Michael Foord wrote:
> David Cournapeau wrote:
>> Hi there,
>>
>> I am using rest2web for my own website, and it is working great, but
>> I have one problem. I would like to use my own python functions in the
>> templates, and I don't know how to do that. I manage to use my macro in
>> a index file doing {print_hello}, but I cannot make it work in a
>> template.txt (using <# print_hello() #>).
> This should work. You should either import or define the function in the
> template.
What do you mean by import ? The problem really seems to be related to
being able to add my function in the "template's namespace".
> <#
> def print_hello():
> print 'hello'
> print_hello()
> #>
This works without any problem. What I don't manage to get working is to
define the print_hello in my macro file, and use it in the template: I
have the print_hello in a macro file, the macro is set in my .ini file,
I can use the function in index.txt, but in template.txt, I got a
NameError: name 'print_hello' is not defined.
cheers,
David
|