1

recently I began to create a REST API with Django REST Framework. I want to implement an authentication system but I have several doubts (The tutorial provided by the Framework is not so concise).

I'd like that every users that want access to my API need a token. These are my questions:

  • Would I need to create a model which keeps the users data? (User, email, token, etc)
  • How can I relate each model with each user?

1 Answer 1

1

The best idea is to use token authentication. It works with default djangos User model out-of-the-box and doesn't need to create any other models. When you create an instance of User you pass an email along with the password and create an instance of Token that is bound to newly created instance of User. So:

  1. No, the models are already shipped with Django.
  2. You just need to establish a relationship.

If you need to keep any other data related to User here's a piece of documentation you need. Have a look here as well. This is how creating an User instance along with the Token is created in codepot.pl workshops backend.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.