dimanche 1 décembre 2019

how to use django achieve auto login in a website [duplicate]

This question already has an answer here:

I'm doing a website to collect my partners' request.And i want the web can identify who login the web once he/she open my website.

For example,you open an website,and you can see the greeting'Welcome,XXX(your name)'.What I want is this,to identify automatically a username or a hostname not manual input username/pwd.Could I get these in the http request headers?or other header info send to server?My friend say to get environment variable can do this,but i don't know how to.I tried request.user or request['username'],but i can't get username.It return nothing.

Purpose of the auto function isn't to get user info from a existed user DB,and also i don't have one.But hope to get client username or his/her PC's hostname.

By now I don't know how to do this.Possible solution I think can work are:

1.Use cookie.I had try this but not success.I find no info in the cookie my brower send to server,i only can find is a crsftoken code and i don't know how to go on with this situation.I try to go through request.META['somefield'] to get some info,I can find many info only escape username,hostname,remote_name.Result also returns nothing.

2.Use session.I think there may have username/hostname in session.But i don't know how to get all info in a session.I know when use py manage.py migrate,a session table will auto generated.I try to search in it but i can only find 3 nouseful column,which are session_key,id,other(forget name).

Could you help me or tell me how to achieve this?

Some django runable code is better.

Thank you so much!




Aucun commentaire:

Enregistrer un commentaire