Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

151
Views
How to authenticate a user using django rest framework

I am trying to authenticate a user using django rest framework and authenticate import below but for some reason i keep getting null as a result when i check the front end with reactJS, i am referring to the variable logged_in_used below:

from django.contrib.auth import authenticate

...

if request.method == "POST":
        username = request.data.get('username')
        password = request.data.get('password')

        get_user = User.objects.get(username=username)
        logged_in_used = authenticate(username=get_user.username, password=get_user.check_password(password))

         ...
         # data with token dictionnary
         ...

         result = (data_with_token, logged_in_used, status.HTTP_200_OK)

Is there something that i am doing wrong here?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

try it like this

from django.contrib.auth import authenticate, login

...

if request.method == "POST":
    username = request.POST['username']
    password = request.POST['password']

    logged_user = authenticate(request, username=username, password=password)

    if logged_user is not None:
        login(request, logged_user)

from here you can redirect or whatever else :)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!