advice about `correct' use of decorator

Gerardo Herzig gherzig at fmed.uba.ar
Thu Aug 16 18:30:07 EDT 2007


Steven Bethard wrote:

>Gerardo Herzig wrote:
>  
>
>>Hi all. I guess i have a conceptual question:
>>Im planing using a quite simple decorator to be used as a conditional 
>>for the execution of the function. I mean something like that:
>>
>>@is_logued_in
>>def change_pass():
>>   bla
>>   bla
>>
>>And so on for all the other functions who needs that the user is still 
>>loged in.
>>
>>where obviosly the is_logued_in() function will determine if the dude is 
>>still loged in, and THEN execute change_pass(). If the dude is not loged 
>>in, change_pass() is NOT executed at all. Instead, it will be redirected 
>>to the `login' screen.
>>
>>Something in my mind tells me that this is not the pythonic way...But i 
>>like the idea, so please tell me that im in the right way :)
>>    
>>
>
>Django does it almost exactly this way:
>
>http://www.djangoproject.com/documentation/authentication/#the-login-required-decorator
>
>STeVe
>  
>
Great! So from now on, my idea is labeled as `djangothic' :)
Thanks a lot!

Gerardo



More information about the Python-list mailing list