Tuesday, May 10, 2011

How do you apply a decorator to all views in a views.py file?

I have a decorator I'd like to apply to every view in a given views.py
file. Is there an elegant way to do that in Django?

I searched Google and the docs but didn't find anything.

So, I wrote some code which works and demonstrates what I'm trying to
do, but it's really ugly.
http://dpaste.com/hold/540845/

Is there a good way to do this?

If you're using __all__ in views.py (which is a great idea anyway), it
can be MUCH simplified:
http://dpaste.com/540853/ <-- MUCH MUCH better!

The latter dpaste just might be the hot ticket. But I'm still sending
this out just in case there's a "best practice" for this.

Thanks,
Shawn

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate