开发者

Passing parameter to load data from DB after login with Django Auth App

开发者 https://www.devze.com 2023-04-07 16:26 出处:网络
I am new user of Django. I want to use the built in Django Auth app for secure login. However, once a user logs in, based upon the username, I want to load it\'s data on the first page (lets call it

I am new user of Django.

I want to use the built in Django Auth app for secure login. However, once a user logs in, based upon the username, I want to load it's data on the first page (lets call it welcome or home page). If I write my own login, I get stuck with URLs. All my pages become http://127.0.0.0.1:8000/login/..... I don't know where this /login/ comes from (it's written in settings file but who calls it I don't know) so after losing ho开发者_StackOverflow中文版pe, I went for Auth login again.

I am sure there is a nice and easy way to retrieve the username but where should I write this code? in the login view of Auth app? would then that code will become part of my application?


Information about the user that's currently logged in is stored in the request.user object (request being the first parameter of every view function). request.user is an instance of the User class from django.contrib.auth. So, you can pass the user object to your templates and make all the information about the logged in user avalable that way (user.username, user.email, etc).

0

精彩评论

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

关注公众号