Conditional decoration

Jeremiah Dodds jeremiah.dodds at gmail.com
Mon Jun 18 14:38:16 EDT 2012


roy at panix.com (Roy Smith) writes:
> 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

You could write a decorator that takes the value of the flag and either
does nothing or decorates it's target function.


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /