Using login_required decorator

48 views
Skip to first unread message

Rootz

unread,
Dec 1, 2014, 6:59:00 PM12/1/14
to django...@googlegroups.com
I have a small project but I am trying to restrict access on some of the django app urls to login users only. The problem is that when I hit a page that requires login users I expected that they(users) are redirected to the login page however that is not the case of what happens instead they are redirected to an example url link like this '/login?next=/detail/1/' with an error message as stated "TypeError at /login/ object() takes no parameters" 

The django project url

(r'^detail/(?P<pk>\d{1,10})/$',login_required(views.DetailViewMember.as_view)),

url(r'^login/$',views.members_login,name='login'),

The Login View Function

def members_login(request):

    if request.method == 'POST':
        password = request.POST['password']
        username = request.POST['username']
        user = authenticate(username=username,password=password)

        if user is not None:
            if user.is_active:
                login(request,user)
                return redirect('members:index')
            else:
                #inactive users required to re-register
                return redirect('members:index')#render(request,'members/login',dict(loginErr=True))
        else:
            #no account required to register to create one
            return redirect('members:index')
    
    else:
        #test if login is a regular get request then redirect
        return redirect('members:index')

Can you explain to me why is it the I am getting this error?

Thank you
Message has been deleted

Daniel Roseman

unread,
Dec 2, 2014, 7:22:30 AM12/2/14
to django...@googlegroups.com
On Monday, 1 December 2014 23:59:00 UTC, Rootz wrote:
I have a small project but I am trying to restrict access on some of the django app urls to login users only. The problem is that when I hit a page that requires login users I expected that they(users) are redirected to the login page however that is not the case of what happens instead they are redirected to an example url link like this '/login?next=/detail/1/' with an error message as stated "TypeError at /login/ object() takes no parameters" 

The django project url

(r'^detail/(?P<pk>\d{1,10})/$',login_required(views.DetailViewMember.as_view)),

 
This has nothing to do with the decorator. You need to *call* the as_view method:
  
(r'^detail/(?P<pk>\d{1,10})/$',login_required(views.DetailViewMember.as_view())),
--
DR.

Rootz

unread,
Dec 2, 2014, 10:09:35 AM12/2/14
to django...@googlegroups.com
Thanks I got it to work...
Reply all
Reply to author
Forward
0 new messages