Build Login API in Django and Django Rest Framework || How to

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 ก.ย. 2024
  • amzn.to/46lefoL : Buy keyboard
    Hi Everyone,
    In this video, I am going to show you how to build an API to login into Django using Python, Django, and Django Rest Framework. It is very easy to create token-based API authentication in Django using Django, Django Rest Framework, and Simple JWT plugin which is demonstrated in this video. I am using python 3 and Django 3 and Django Rest Framework 3 (drf) for this project.
    Important Links:
    Git repo: github.com/Kir...
    Facebook group: / 906892293502457
    Telegram channel: t.me/djangodrf01
    My laptop: amzn.to/3641BgO
    Second Monitor: amzn.to/3qIeF4X
    Keyboard: amzn.to/3Ad7R3B
    Mic: amzn.to/3yfIkVH
    SSD: amzn.to/3hb4By7
    External HDD: amzn.to/3wcMtYU
    Amazon Prime Membership: amzn.to/3qDnahG
    Audible subscription: amzn.to/2TweLQR
    If you have suggestions for the next video please feel free to comment them down.
    NOTE: We'll try to create better videos, so stay tuned.
    Thank you, everyone, for watching this video.
    If you got any questions, do comment below.
    Do like, subscribe and share more such videos on Django and Django Rest Framework.
    Tune in Again!
    simple jwt django rest framework, jwt authentication django rest framework, django jwt authentication tutorial, drf jwt authentication, how to create login api in django rest framework

ความคิดเห็น • 46

  • @CodewithSJ
    @CodewithSJ  11 หลายเดือนก่อน +1

    Thank you for watching this video.
    *Buy my keyboard:* amzn.to/46lefoL

  • @CodewithSJ
    @CodewithSJ  2 ปีที่แล้ว +1

    *Django Rest Framework User Registration (Signup)* : th-cam.com/video/4Azu7AX0mls/w-d-xo.html

  • @chrissati6713
    @chrissati6713 2 หลายเดือนก่อน +1

    I have have such many videos up to no avail... this your video save my project,,,, thank you so much

    • @CodewithSJ
      @CodewithSJ  หลายเดือนก่อน

      Glad it helped!
      Please do susbcribe for more such content.

  • @ridersofficial5638
    @ridersofficial5638 2 หลายเดือนก่อน +1

    Explain with font end part also how to render data in temple

    • @CodewithSJ
      @CodewithSJ  หลายเดือนก่อน

      Sure! Will do soon.

  • @RandomMusicD
    @RandomMusicD ปีที่แล้ว +1

    Thanks so much, i needed it

  • @athulyajose
    @athulyajose 7 หลายเดือนก่อน +1

    17:45 I tried to POST but I’m getting the output containing detail code ans messages where the detail contains- “given token not valid for any token type”. Also i cant add tokens in the local host

    • @athulyajose
      @athulyajose 7 หลายเดือนก่อน +1

      I tried to get new tokens for admin and it worked! I was able to create new user through postman! Thanks

    • @thorodinson8187
      @thorodinson8187 7 หลายเดือนก่อน +1

      ​@@athulyajose Can you give the solution. I'm facing same issue

    • @CodewithSJ
      @CodewithSJ  6 หลายเดือนก่อน

      Create a new superuser from django shell.
      Login as superadmin.
      Generate a token and use that token in the postman.

  • @deed_it
    @deed_it ปีที่แล้ว

    what's next after this, how should I integrate this into my web app. or is there another for logout? and register?

    • @CodewithSJ
      @CodewithSJ  ปีที่แล้ว

      Yes, this is to be integrated in any mobile app or front-end app.
      Registeration video: th-cam.com/video/4Azu7AX0mls/w-d-xo.html

  • @classicclassic1474
    @classicclassic1474 ปีที่แล้ว

    👍👌

  • @19betim
    @19betim ปีที่แล้ว

    question here, why you does not encrypt the password?

  • @kahi_chalte_hain___
    @kahi_chalte_hain___ 11 หลายเดือนก่อน +1

    Everything is greate, but can anyone tell me that how can any user can login using Username and password within Postman

    • @CodewithSJ
      @CodewithSJ  11 หลายเดือนก่อน

      it is very easy.
      In "Authorization" select "Basic Auth" and you will get option to enter username and password

  • @noscopedemon4308
    @noscopedemon4308 ปีที่แล้ว +1

    At 15:40 I am still getting "{
    "detail": "Authentication credentials were not provided."
    }" stuck since morning, plese help

    • @CodewithSJ
      @CodewithSJ  11 หลายเดือนก่อน

      While doing the AJAX request, please provide the token

  • @mista_ia
    @mista_ia ปีที่แล้ว +1

    Amazing.. First Thanks for that !
    I am using custom user (extended from AbstractBaseUser) and I have users in my DB with all requirements (is_active, hashed password, etc.) but when I enter credentials (email as username and password) to token view I am still getting "No active user with those credentials."
    Any Help please ?

    • @CodewithSJ
      @CodewithSJ  ปีที่แล้ว +1

      You can login from superuser and check if that user is active or not and then try to generate the token.

    • @mista_ia
      @mista_ia ปีที่แล้ว +1

      @@CodewithSJ all the users are active, I believe that the problem lays on the fact that I have extended the original user model since none of login works (from /admin, browsable api of DRF, or even a login view I created for test).
      I will open a stack for better understanding!

    • @CodewithSJ
      @CodewithSJ  ปีที่แล้ว

      okay, please do post the link here as well.

    • @mista_ia
      @mista_ia ปีที่แล้ว +2

      @@CodewithSJ Nevermind. My bad, I was hashing the password twice with set_password and make_password while I do not even need them since I am using the default UserManager.
      Thanks for assist !

    • @CodewithSJ
      @CodewithSJ  ปีที่แล้ว +1

      Nice to hear that!

  • @salmanr
    @salmanr 2 ปีที่แล้ว

    Hey, one doubt, So here "api/token" is the main login API and "/user" is used to get the details of the user? Am i correct? and also how we can access other user information with only one bearer token? its wrong right?
    And let say i want to register new user, how user will get token that time?
    I am new to Django please help.

    • @CodewithSJ
      @CodewithSJ  2 ปีที่แล้ว

      So here "api/token" is the main login API and "/user" is used to get the details of the user? Am i correct?
      Yes, this is correct.
      and also how we can access other user information with only one bearer token? its wrong right?
      I think you just have to do a retrieve API call with a specific user id, and users id's can be found from the list API
      No, I don't think it is wrong. Usually, admins have to do such a thing.
      And let say i want to register new user, how user will get token that time?
      Technically this should be possible, but since we are using the plugin so after the registration of the user, you will have to explicitly call the plugin's internal methods which will generate the token, and then you will have to return the token to the user.

  • @deed_it
    @deed_it ปีที่แล้ว

    Hello can I ask what is the purpose of this and how should I proceed after following this

    • @CodewithSJ
      @CodewithSJ  ปีที่แล้ว

      This is the main logic of how login works using REST API. now you can use this anywhere (eg. front-end app, mobile app)

  • @gokulsuresh1888
    @gokulsuresh1888 ปีที่แล้ว

    Hi..how can i use this api in frontend like on a html,css login page

    • @CodewithSJ
      @CodewithSJ  ปีที่แล้ว

      Hey,
      For that we will have to create Javasctip function and use AJAX/AXIOS to call the APIs from the frontend and send and/or receive data

  • @vvxyow2400
    @vvxyow2400 ปีที่แล้ว

    Really well-explained and thorough guide 10/10. Thank you so much!!

    • @CodewithSJ
      @CodewithSJ  ปีที่แล้ว +1

      Glad you liked it!

  • @abhishekozha8555
    @abhishekozha8555 ปีที่แล้ว

    how do you open api tokens and others,,it doesnt show on my

    • @CodewithSJ
      @CodewithSJ  ปีที่แล้ว

      If you see the settings.py, I have specified REST_FRAMEWORK configuration.
      Please use that then api token will be visible.

  • @sandeepmishra1390
    @sandeepmishra1390 3 ปีที่แล้ว

    Make. Video on youtube

  • @martinwanjia990
    @martinwanjia990 2 ปีที่แล้ว

    why would i need a token to register a user?

    • @CodewithSJ
      @CodewithSJ  2 ปีที่แล้ว

      We don't need token to register user

  • @adwaitahegde
    @adwaitahegde 3 ปีที่แล้ว +1

    Nice video! 😃

  • @mattiastofte7457
    @mattiastofte7457 2 ปีที่แล้ว

    Hi, everything works except that you get HTTP 200 OK (Allow: GET, POST, etc.) on localhost:8000/user/ even if you are not logged in.

    • @mattiastofte7457
      @mattiastofte7457 2 ปีที่แล้ว +1

      I found the error, it was that I wrote permission_class = (IsAuthenticated,) instead of permission_classes = (IsAuthenticated,)

    • @CodewithSJ
      @CodewithSJ  2 ปีที่แล้ว

      Glad to hear that you were able to find and fix the problem