Reputation: 967
I'm very new to Django. First of all, I need to tell you what I'm having so far. I have a front end, I added django-registration module.
Now I want to add some private page for users after logging in.
As common sense in other programming languages, I will check the session to see if the user has logged in or not. If not, redirect them to the login page. If yes, display the private page http: // your site. com /private_page
My question is do you have any more elegant solutions to this so that the code can be cleaner and more maintainable. I don't want to keep checking session variables all the time for every secured page.
Kind Regards,
Upvotes: 2
Views: 77
Reputation: 4047
The @login_required
decorator is what you are looking for. More info at https://docs.djangoproject.com/en/1.3/topics/auth/#the-login-required-decorator
Upvotes: 4