I want to set the rights of my user in the session after a successfull login. For now I'm doing it in the view to which the user is redirected by default after the login. But this does not work if the user navigates directly to a view, logging in and passing the defa开发者_StackOverflow中文版ult view.
Where do I have to place a initial session setting, ensuring that it is always set?
I'm using djangos build-in login.
(r'^accounts/login/$', 'django.contrib.auth.views.login', {'template_name': 'login.html', }),
A piece of middleware is probably your best bet - just have it check for whatever you're storing your permissions in, and then initialize it if the user is authenticated and it doesn't exist yet.
i think you can use decorators on each view like @login_required
so you ensure that your user is logged in each view... Regards
精彩评论