On Tue, Feb 8, 2011 at 11:34 PM, Pascal Germroth <funkyco...@gmail.com> wrote: > Hi, > > I'm new to Django, but since this project will take a while I'm already > using 1.3 alpha since it will probably be released when I'm done… > > As I understand it, the preferred method now are class-based views. But > I seem to be missing some kind of AuthenticationMixin… right now, have > to override `dispatch`, add the authentication decorator as one would > for function views, and call super. > > To make things a bit easier, I'm about to write my own mixin for that so > I only have to provide a method that checks if credentials are OK. > > > Or am I doing this completely wrong?
You're not doing anything wrong -- you've hit one of the slightly sharp corners of class-based generic views. You can still use a decorator -- but at the point of deploying a view. login_required(MyView.as_view()) You can't decorate the MyView class itself -- Django doesn't provide the tools to turn a view decorator into a class decorator. As you've noticed, you can override the dispatch to decorate the view as required, and if you have a common authentication pattern, you can put that logic into a mixin. In a general sense, the problem that Django has as a project is that while login_required is a very common decorator for checking authentication, it isn't the *only* decorator that can be used. Authentication -- and decorating views in general -- is a fairly common patterns, though, so we obviously need to do something to address this. There have been a couple of discussions about the best way to implement that feature. However, these discussions are a work in progress. In the interim, a mixin is probably the best approach. Yours, Russ Magee %-) -- 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+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.