A webpy Templetor question

yongzhi.chen at gmail.com yongzhi.chen at gmail.com
Tue Jul 14 01:13:05 CEST 2015

Hi all,

I want to display/update several metrics in a normal page (not in a webpy form). These metrics got updated every minute and were stored in a log file. I prepared a function to open that log file then analyze the last several lines to collect them. I want these metrics got updated in every page load/refresh.

The first method I considered is to utilize Templetor (http://webpy.org/docs/0.3/templetor).  I used $code block in the template but figured out soon that this solution won't work for the security reason. In my function I use open which is prohibited by webpy.

Then I thought of `Import functions into templates` (https://github.com/webpy/webpy.github.com/blob/master/cookbook/template_import.md). In my case, there is no argument for that function. I followed the instruction but got the following error.

    checknow() takes no arguments (1 given)

#in my application.py:
def checknow():
    return TN_str

render = web.template.render('templates/',globals={'stat':checknow})

#in the template:
$def with(checknow)
... ...
    <h1><div>Test: $stat(checknow)</div></h1>

By the way, how to refer multiple values of the function checknow()? The function checknow() should return multiple values in the real case. Could you please help me out? Thanks a lot.

Best Regards,

More information about the Python-list mailing list