I'm trying to convert some of my django views over from function based views to class based views and I've run into a small problem.
My OO is kind of weak and I think the problem is that I've lost track of where things are going.
I have a custom login decorator that I need on the views so I have...
First I have the View class from this example http://www.djangosnippets.org/snippets/760/
Then my view class looks like this...
class TopSecretPage(View):
@custom_login
def __call__(self, request, **kwargs):
#bla bla view stuff...
pass
The problem is that my decorator can't access request.session for some reason...
My decorator looks like this...
def myuser_login_required(f):
def wrap(request, *args, **kwargs):
# this check the session if userid key exist,
# if not it will redirect to login page
if 'field' not in request.session.keys():
return wrap
I think it's something simple that I'm missing so thanks for your patience everyone!
UPDATE: Ok so here's the error that I get...
"ViewDoesNotExist: Tried TopSecretPage in module projectname.application.views. Error was: type object 'TopSecretPage' has no attribute 'session'"
I simplified the decorator as well to look like this....
def myuser_login_required(request, *args, **kwargs):
# this check the session if userid key exist,
# if not it will redirect to login page
if 'username' not in request.session.keys():
return HttpResponseRedirect(reverse("login-page"))
return True