简体   繁体   中英

Angular 2 frontend django 2 REST framework backend user auth

I'm new to Django and JavaScript, so please forgive me if this is an obvious question.

What is the best way to authenticate users?

I can only find posts about using this which doesn't support django 2.

Thanks for your help.

django-rest-framework provides several solutions for authentication. I recommend to read carefully the docs : http://www.django-rest-framework.org/api-guide/authentication/

I've already used Token authentication on several projects and it works fine:

You need to install the rest_framework.authtoken app in your project. This app is provided with django-rest-framework

Then you need create a token for every user. There are several ways described in the docs.

On the client side, you need to implement a login form. Your backend will check user and password and gets back the user token.

Then you can pass this token in the header of every request:

Authorization: Token value-of-the-token

Make sure to use https if you use Token authentication.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM