开发者

django when to set session after login

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜