Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #93768 > unrolled thread

A webpy Templetor question

Started byyongzhi.chen@gmail.com
First post2015-07-13 16:13 -0700
Last post2015-07-14 10:59 +1000
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  A webpy Templetor question yongzhi.chen@gmail.com - 2015-07-13 16:13 -0700
    Re: A webpy Templetor question Chris Angelico <rosuav@gmail.com> - 2015-07-14 10:59 +1000

#93768 — A webpy Templetor question

Fromyongzhi.chen@gmail.com
Date2015-07-13 16:13 -0700
SubjectA webpy Templetor question
Message-ID<fc88437a-7776-4836-a57e-10c67e8f5925@googlegroups.com>
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,
-Yongzhi

[toc] | [next] | [standalone]


#93769

FromChris Angelico <rosuav@gmail.com>
Date2015-07-14 10:59 +1000
Message-ID<mailman.473.1436835551.3674.python-list@python.org>
In reply to#93768
On Tue, Jul 14, 2015 at 9:13 AM,  <yongzhi.chen@gmail.com> wrote:
> #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>

You've effectively taken a reference to the checknow function and
given it the name 'stat'. So when you call $stat(), I would expect it
to call checknow() with exactly those arguments. I don't know what
"$def with(checknow)" means, but if you figure out what checknow is
inside there, then you'll know whether you want any argument at all. I
suspect just "$stat()" may well do what you want.

ChrisA

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web