@login_required
decorator. Let me show you how I have it setup:
My "Profile" view is the profile a user sees once they are logged in to then have the ability to edit their information so obviously this needs to have the login required decorator because they shouldn't be able to get to this point unless they are logged in or are authenticated but here it is:
@login_required
def Profile(request):
contextdata = {}
if request.user.groups.filter(name='Athletes').exists():
return render_to_response('profile.html', contextdata, context_instance = RequestContext(request))
else:
contextdata = {'Error': 'Error'}
return render_to_response('profile.html', contextdata, context_instance = RequestContext(request))
On Monday, December 1, 2014 6:59:00 PM UTC-5, 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)), url(r'^login/$',views.members_login ,name='login'),The Login View Functiondef 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-registerreturn redirect('members:index')#render(request,'members/login' ,dict(loginErr=True)) else:#no account required to register to create onereturn redirect('members:index')else:#test if login is a regular get request then redirectreturn redirect('members:index')Can you explain to me why is it the I am getting this error?Thank you
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/90f90d6c-e1a6-4893-97db-e2e6d5f48a7d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment