How do I require a login for a user in Django?
Posted
by
Di Zou
on Stack Overflow
See other posts from Stack Overflow
or by Di Zou
Published on 2012-06-12T04:37:29Z
Indexed on
2012/06/12
4:39 UTC
Read the original article
Hit count: 134
In my urls.py I have this:
(r'^myapp/$', 'myapp.views.views.index'),
(r'^myapp/login/$', 'myapp.views.views.login_user'),
In my settings.py I have this:
LOGIN_URL = '/myapp/login'
In my views.py I have this:
@login_required((login_url='/myapp/login/')
def index(request):
return render_to_response('index.html')
def login_user(request):
#login stuff
return render(request, 'registration/login.html', {'state':state, 'username': username})
I can go to mysite.com/myapp/login
and the login page works. However, when I go to mysite.com/myapp/index
I do not get redirected to the login page even though I am logged out. Why is that and how do I fix it?
© Stack Overflow or respective owner