Django REST Framework | User Register Login Logout API

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys and welcome so this is the series of Django rest framework tutorial and in this video to told you you will learn about user registration login logout epa's I have written this blog on my website study yang comm links will be in description so let's get started okay so there will be installing these libraries okay so we'll copy this library and we are going to install our libraries in virtual environment okay install ones Django rest framework is installed we will be using Django rest Knox which is a token-based authentication so in this tutorial example we will be using two can be used authentication okay so we'll install this one also Knox library then we need to create a jungle up so first we'll create the app Django admin start project D are F so our project has been created and its name is dr F okay now inside the our F we have installed apps and inside that we will be pasting this two lines okay so here it is now we need to add this thing okay so guys this is a rest free book which is following token-based authentication okay so for now we have commented these things but if you guys want to use session be is authentication then this line should be there okay for now we are using knobs to can be used authentication so we'll save this one and we are ready to go now we will be creating one called accounts Django admin start-up accounts and we will be beasting this up in our installed apps okay so the name of this app might be different in your scenarios okay now in this app we will be going to the views okay first we will be creating a serialize earth I so it should be Syrian Isis as Syria Isis okay now we will be pasting the score inside that thing so basically we are creating a serial I surf for our register API okay then inside the views dot pi there will be pasting this code so in V dot PI P is this code so this is our rest EPS which we have created now what we'll do we'll first register our URLs dot pi in our main URL Scott PI so first we'll include then we'll copy this path and remove this thing include and in here accounts dot URLs see now we will copy this file and we'll paste it in things we will be adding this path okay so we can directly copy this thing okay save now we are ready to go okay so now what we'll do we'll run this over and check if there are any errors okay and we don't find in errors so we can go to this URL because our URL is API slash register so here we can see the register API okay so similarly you can see postman okay in postman we can register and this link this tutorial link will be in the bottom there will be a get link so you can go through the code whatever we have created and for now I can show you one example like I have created the api's so in register so I have not created any register yes so what we'll do we'll create one EBI okay and we'll see what all fields are required okay so we can copy this thing and we can give it as post in body we can give it as raw or you can directly give it here as username and then username as admin then password as password and email okay now we have done this now I will copy this URL and we'll paste it here okay we'll rename this as register okay and now we'll send this file so in here the content type is this by default it comes in postman and we'll send it okay so no user earth user has been from so the problem is here is that we have not migrated our fields so by managed of my make migrations migrate okay now we have created this thing now we'll send it okay again run this over and send okay so this is how our register user resistor that's done okay so this is the authentication key so if you can use this authentication key for login also so now we'll go to the login logout API authentication so in accounts use dot five we'll paste this code and basically this is the view code where we are overriding the Knox classes so we can keep the score here we are using Knox login view and a Knox login view what we'll do if you can see here this code this code is used for logging okay so guys if you guys are using session B is login so this can be a very useful tip for you okay now what you can do we can copy this URL paths in our views you are H dot PI here okay now we can give the login API and one more thing the Knox views see if this one and you know we are done now let's say we can go to this URL okay so similarly you can go in postman and you can do things also now we can the the password which we have created the username which we have created it should be in this format okay so I think we have created the password and the username with the same views I use it use that default and host okay so we have logged in and if you see we have got a token and expiry similarly we have done for logout also so what we'll do I'll show you an example where how a logout can be used okay so if you see here love out in here I'll create one so in here I'll give the URL and the URL will be knockout and here what we'll do we'll give or thrice token so to access the authentication is authenticated apps we need to use authorization and what we'll do we'll use this code this token and here as we are using Knox we will be using token space and the code and said okay okay so it is giving me error like get method is not allowed so we'll change it to post and you're done so we are not getting any response this means we have been logged out okay now we'll what we'll do we'll check the second one okay so this one is used for logout or let's see if if a user has logged in many times in different browsers we can use this thing to logout from every browser so guys this was the first part of our Django rest framework tutorial and you can continue for the next part where we will be teaching you Django rest framework tutorial change password and reset password thank you guys if you like my video give a like thumbs up and comment below so that I get motivated I create such wonderful content for you thank you guys bye bye you
Info
Channel: StudyGyaan
Views: 93,262
Rating: undefined out of 5
Keywords: django rest framework, django api, django rest framework authentication, django rest login, django rest logout, django rest user registration, django rest knox
Id: Cw_jSc1NGdo
Channel Id: undefined
Length: 11min 44sec (704 seconds)
Published: Tue Jun 30 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.