Django rest framework project tutorial Series. Getting Started [1]

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey what's up guys chris here in this tutorial series we are going to be building an experienced income recording api so users can come and be able to record their income and expenses all right so for us to be able to do that you're going to need to build up an authentication system so we'll have users register we'll have them login we'll have them change their password if they forget we'll have them verify their email and all that fun stuff so right here we'll have an endpoint that will enable a user to refresh their token so if you come to think of it the way token authentication works is you log in you get the token you use that access token and then when it expires maybe the front end can lock the user out but with our refresh token the front-end can actually reach out to the back-end and refresh this token in the backbone such that the user keeps access okay so we'll implement that so from there then we will enable users to sign in and then create their records they will be able to create read updates expenses do that for their income and then we'll provide some endpoints to give some data that can easily be visualized like on the front end like using chats all right so after that we will deploy the application and from then then we will first document it so for example here you can see that this is a solid documentation if you're not familiar with that basically it's a tool that allows us to construct api documentation really easily we'll create this ui such that now if if you finish like building the api and give them give it away someone can actually come in here let's say you have someone on the front end and they can see like the models you have the validations you're enforcing and so they can know how to enforce them on the front end yeah so this this always comes in handy this documentation actually also can provide a way for people to test out the api for example here if i click here you can see more details like what the back end will expect and yeah you can try it out if i click try it out you can see that this is a register endpoint we can provide an email username and password and then we can try it out basically so when i do that notice that i get a 201 meaning that then i get a user created the new created user if i try to do it again you see i get a 400 i get these errors yeah so it always comes in handy it can do the job the testing job for for you if if you're testing out the api all right so sounds good and all so after registering the user we'll be able to send them an email which they can use the the code we send them to come and verify so the user token we send them actually let me try it out here so from here let me use an email that actually exists so please all right so let's try this one click execute and then the user is created and notice how fast the response has come even when in the background we are doing things like sending an email this is kept like really fast the ui is kept like really fast so i'll show you some techniques you can use to do that now if i go to my email you can see that we have a new email so this one gives us a token that we can use to to verify our account so i'm going to copy the token since this is an api i'm going to copy the token and then right here so you have this endpoint to verify an email so if i click on it and go to try it out you can see that we can pass a parameter so here and put the token and then click execute so when i do that you see we get account activation successful meaning that now this account is successful and can be used to login all right so now if we go to login endpoint click try it out so i use my email and we'll create a custom user model on with django so we can allow users to use image login so here if i use that email click execute now you can see this is not working so let's see you may create story oh this should be about that so let's try again all right so you can see that now we login we get a 200 and then we get some few things one of them is the email the username and then the tokens so notice how tokens is actually an object that contains two values which one of them is a refresh and another one is the axis so on the front end the user would have on the front end would have to save both of these such that when this expires we can refresh it using this without having to log out the user which always comes in handy for the user experience so once we log in now we can be able to create we can once we login we can be able to now start creating expenses so i'm going to copy the access token because it's going to be needed i'm going to copy it out and now if i come and collapse this let's say i want to get all my expenses if i click there and then click try it out so we are going to paginate the api for example here you can see we can we need to fish by page so if i put one you can see that authentication credentials are not provided and then notice that all our errors come in a key errors and all our successful responses come in a key data so i will be showing you how you can can use the renderer classes in the rest framework to construct really consistent responses which always like makes it easy to implement on the front end so here i'm going to come to authorize and then here we are going to set up the documentation to accept to accept a jwt authentication such that users can come here and then test it out so if i come back to the expenses click execute you can see that we get an empty we can get we get a result 200 and then we see the count the the pagination links and then the results are which is empty at the moment so let's try to create some expenses so if i go to post and then try it out so here we need to of course this is this is all validated if i try to execute you consider to see the amount is not valid because it should be the flow should be an actual number so if i put like 300 000 try execute you can set it gets created we get the data key and then these details all right so if i do this for more times you should be able to see that now if we go to our endpoint to get uh click execute you see that we get all our expenses and then this will be donated their pagination links all right so it's gonna be almost the same for the other endpoints especially the income one yeah so we can get one delete one update certain fields of it all right so it's going to be almost similar and then here we'll be building out our statistics endpoints to give the user some data that you can graph on the front end which i think we will be building in the in the future all right so we're going to go ahead and start building this all right so i'm here in my terminal the first thing we're going to need to make sure we have is python so to make to check you can run python version so you will notice that i have python 2.7 but if i run python 3 version you can set now i have python 3.7.7 so this is what you're going to be using so the first thing you're going to need to do since you have python 3 you're going to create a virtual environment using the virtual env module so python 3 ships with virtually nv it's a tool in the standard library that can enable us to create virtual environments we're not going to be using things like buy em or pip in we're going to just stick to this stick to the basics before we do that i'm going to create a folder here make that i'm going to call it django apps then i'm going to cd into django apps and in here i'm going to use python 3 to create a batch environment so python 3 minus m and then we use virtually nv and then we give the virtual environment name this is where like all our project files will be stored i'm going to put it to them all right so that creates a virtual environment so in here we need to actually activate it which you can do by doing source then being activated so when you do that you can see that now it gets activated you can see from here so now we need to install django so when we create a batch environment it actually sets up pip so if you run pip version you can see that we have pip so now we can use pip to install django alright so once we are done here now we can use django to create a jungle project so we can do django admin stats project i'm gonna call it income expenses api oh it should be start project start project project all right okay so if we run ls you can see that we have the jungle project created so i'm going to see it into the jungle project so cd income expenses if i do analysis you can see that you have access to manage this py so here you can run the python manage that py by doing python so manage poi then we want to run run server so this sets up our server if you click on the link you can set to have django installed everything is up and running so the next one will start by creating our custom user model so i'm going to be posting the video here if you haven't subscribed to the channel i recommend you subscribe just so you can keep in the loop as we post new videos i'll see you guys in the next one bye
Info
Channel: Cryce Truly
Views: 34,689
Rating: undefined out of 5
Keywords:
Id: rJWAGQ0JxxI
Channel Id: undefined
Length: 10min 48sec (648 seconds)
Published: Sun Jun 14 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.