0

I had been using Django and it's powerful templates for quite some time but suddenly I had to Switch to the Front End languages and technology (completely different and new) that includes JavaScript, jQuery and AJAX. I want to access my API data at the front end using HTML,CSS,Javascript,Ajax,jQuery (whichever combination is suitable)

I am able to get my data and manipulate it easily without any difficulties using jquery and Ajax by using simple $.ajax() method but the problem is that I do not have any clue about how to get the data that requires permissions?


{
    "detail": "Authentication credentials were not provided."
}

What is the procedure to access this data? I am using Token Authentication provided to each user. How can I access the Token if I am not using Python and Django views at the front End? DO I have to login with every request? What is the actual Procedure? Can Someone Guide me through it?

According to Documentations, I am supposed to put the token in header. but How would I get the Token from DB and access it for every user and with every request?

Deshwal
  • 3,436
  • 4
  • 35
  • 94

1 Answers1

0

You can save the token in browser cookies once a user is logged in. After that, you can get the token from cookies using jQuery or any other frontend technology and send along with your ajax request to your Django application or you could use JWT

session vs token auth

CRUD cookie using jQuery

django and cookie

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Albin Antony
  • 775
  • 3
  • 8
  • 21
  • How can I save it in Cookies? I mean what to do? My front end does not use Python or Django. I us simple HTML with jQuery? How do I get the Token from there? – Deshwal Aug 23 '19 at 12:00
  • @Deshwal Please refer the links I've provided. It clearly shows how to set a token in a cookie from Django and read the cookie in jquery – Albin Antony Aug 27 '19 at 09:43