Conditional decoration

Jean-Michel Pichavant jeanmichel at sequans.com
Tue Jun 19 05:01:23 EDT 2012


Roy Smith wrote:
> Is there any way to conditionally apply a decorator to a function?
> For example, in django, I want to be able to control, via a run-time
> config flag, if a view gets decorated with @login_required().
>
> @login_required()
> def my_view(request):
>     pass
>   
Hi,


def my_view(request):
    pass

if flag: my_view = login_required(my_view)

Regards,

JM



More information about the Python-list mailing list