that is how decorators work.

@decorator
def f(): return

is the same as

def f(): return
f=decorator(f)

so the decorator is called upon definitions, not when the function f
is called. unless you make this more complex

def decorator(f):
    def _decorator():
         print 'hello world'
         f()
    return _decorator

Massimo
On Dec 19, 2:30 am, cjparsons <[email protected]> wrote:
> If I have a controller file as below I find that the decorator()
> function is called when any controller in the file is called not just
> the decorated ones. i.e. If I access /application/default/index I see
> "decorator called" as well as when I access /application/default/
> index2. Am I doing something stupid? Thanks, chris.
>
> def decorator(func):
>     print("decorator called")
>     return func
>
> def index():
>     response.flash=T('Welcome to web2py')
>     return dict(message=T('Hello World 1'))
>
> @decorator
> def index2():
>     response.flash=T('Welcome to web2py')
>     return dict(message=T('Hello World 2'))
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to