WEBVTT 00:00.480 --> 00:02.270 So I know this was a little disappointing. 00:02.310 --> 00:04.900 We got to the place where we could show our API. 00:04.950 --> 00:06.240 But there's nothing there yet. 00:06.750 --> 00:08.640 Well, we've got to throw some things in the database. 00:08.650 --> 00:14.910 So I think the first and easiest way to do this is to create a super user and use the admen portion 00:14.910 --> 00:16.380 of Django to our advantage. 00:16.560 --> 00:21.060 So let's go ahead to move back to our terminal, do a control, see to stop the server and let's go 00:21.060 --> 00:23.250 ahead and make a super user for our project. 00:23.310 --> 00:28.740 So and before we do this, we've got to make sure I think we've already migrated our date database. 00:28.740 --> 00:35.620 But let's make sure Python for me, I've got to make sure I have Python three managed up high migrate 00:36.600 --> 00:36.810 and. 00:36.810 --> 00:38.330 Yep, we're all good to go, Kane. 00:38.520 --> 00:46.920 So with this, I'm going to say Python three managed that pie and now I want to create super user. 00:47.010 --> 00:47.970 All one word. 00:48.660 --> 00:52.110 So I'm going to go ahead and just use the name zappy code here. 00:52.260 --> 00:53.850 Feel free to use whatever you'd like. 00:54.510 --> 00:58.260 I'm not going to be using an e-mail with this and I'm just going to use a simple password. 00:58.260 --> 01:02.550 A, B, C, D, one, two, three, four, abc d, one, two, three, four. 01:03.120 --> 01:03.600 Awesome. 01:03.670 --> 01:04.750 It is very common. 01:04.800 --> 01:05.670 Sure you want to use this? 01:05.700 --> 01:06.660 Yes, I do. 01:06.880 --> 01:07.130 OK. 01:07.500 --> 01:10.500 So with that in place, let's go ahead and run the server again. 01:11.540 --> 01:11.790 OK. 01:11.840 --> 01:13.970 Now that's up and running in a new tab. 01:14.660 --> 01:21.520 I'm going to go to a copy that you are l here so that we have it to go to slash admen. 01:22.310 --> 01:27.470 I'm going to log in with my super user, which for me is zappy code might be different for you. 01:27.980 --> 01:31.900 And I'm going to give that a, b, c, d, one, two, three, four, password. 01:32.400 --> 01:37.550 OK, so now that I'm in here, I'll be able to see whatever we have in the database and save things 01:37.550 --> 01:37.820 in there. 01:37.850 --> 01:43.670 But you'll notice we don't have anything showing up for our particular post. 01:43.760 --> 01:47.720 So remember, if you remember this from Django, we've got to go back to this. 01:47.780 --> 01:50.420 Admen dot py file inside of the post app. 01:50.930 --> 01:55.140 And we need to register our classes with the admin. 01:55.190 --> 01:58.230 So we're gonna go ahead and bring in our two models. 01:58.240 --> 02:03.020 You're going to say from models import. 02:03.530 --> 02:06.170 I'm going to bring in post and vote. 02:07.910 --> 02:09.860 Then I just simply need to register these. 02:09.860 --> 02:12.160 I'm going to say admen that site. 02:13.040 --> 02:14.090 Register. 02:15.460 --> 02:21.910 And we'll go ahead and pass in first the post and then we'll copy this line and do it again for the 02:21.910 --> 02:22.240 vote. 02:23.520 --> 02:23.720 Thanks. 02:23.960 --> 02:30.000 So if we save this file and then come back to our Admon and reload, look at that post and votes show 02:30.000 --> 02:30.210 up. 02:30.660 --> 02:35.100 Now our API is supposed to show post objects, so let's go ahead and make a post object. 02:35.520 --> 02:39.960 I'm going to say posts add post the title here is going to be. 02:42.930 --> 02:45.640 A cool Web site to learn. 02:45.780 --> 02:49.450 Code look at me shamelessly promoting my own Web site here. 02:49.740 --> 02:54.060 So this is going to go to zappy code dot com. 02:54.060 --> 03:00.060 And with Django, you, Earl Fields, you have to make sure it's HTP or HTP s with the colon slash all 03:00.060 --> 03:00.720 that jazz. 03:01.320 --> 03:03.120 And we have to pick who who it is. 03:03.120 --> 03:03.820 That's Posadas. 03:03.900 --> 03:08.250 We only have one user right now, so I'm going to pick zappy code, but I'll go ahead and hit save. 03:08.700 --> 03:16.020 So now we can see in the admin side of things that we have an object and if we go back to our API, 03:16.110 --> 03:17.190 I'm going to reload this. 03:18.980 --> 03:19.730 Look at that. 03:20.090 --> 03:21.710 The API is up and running. 03:21.950 --> 03:26.960 We are listing out all the post objects that are there, so let's go ahead and make a new one. 03:27.130 --> 03:29.900 OK, let's go ahead and add a post here. 03:30.340 --> 03:38.510 I'm gonna say a great way to make an API and I'm going to go grab the jingo rest framework. 03:38.540 --> 03:41.060 You I'll post this in here. 03:41.210 --> 03:43.610 Again, this is a zappy code, so I'm going to save this. 03:44.120 --> 03:45.380 Reload the API. 03:46.550 --> 03:47.470 Isn't this awesome? 03:47.480 --> 03:48.200 This is so cool. 03:48.470 --> 03:52.670 And we can do this through the browser or in the terminal here. 03:52.820 --> 03:58.060 If I do a control C and stop, I can say Kerl copy the URL that we have here. 03:59.070 --> 03:59.970 Paste this in. 04:00.570 --> 04:02.160 And now I forgot. 04:02.190 --> 04:08.100 We have to be running the server, so let me run the server in a new tab here in a different terminal 04:08.100 --> 04:08.610 window. 04:08.640 --> 04:17.040 I'm going to say Kerl and then that you are all looking at it brings back the Jason for that particular 04:17.040 --> 04:17.760 API call. 04:17.760 --> 04:18.750 Isn't that great. 04:19.170 --> 04:23.130 This is so cool that we have this up and running now. 04:23.490 --> 04:29.910 Something that I want to talk about this because this is a really big dear deal here is that the Jango 04:29.910 --> 04:36.360 Rest Framework framework makes it so that if we're going to list out some API, for example, to go 04:36.360 --> 04:43.890 to our views here, where we list out all the posts, this whole class base view magically makes it 04:43.890 --> 04:50.580 so that if I visit this, you are in a browser, it will detect that I'm with a browser and it will 04:50.580 --> 04:56.790 give me this really nice detailed page that says, hey, this you are real here, accepts get head and 04:56.790 --> 04:58.420 option requests. 04:58.680 --> 05:02.430 It's going to be Jason objects and it lists shows you a preview. 05:02.460 --> 05:06.420 If you want to show just the raw data, you can go to Jason, which you'll notice that you are all for. 05:06.420 --> 05:11.820 This is, you know, has the little question mark here format equal to Jason. 05:12.870 --> 05:14.690 So this is all baked in. 05:14.700 --> 05:20.400 It can come back just as simple as, you know, the Jason that you see here. 05:20.460 --> 05:25.420 Or you can get this full h t mail layout showing everything inside of here, OK? 05:26.430 --> 05:31.740 So if you go on options, it shows a little bit more details about what things this API can spit back. 05:31.770 --> 05:36.690 But honestly, if if you're not really diving deep into the framework, there's there's not tons of 05:36.690 --> 05:37.860 great information here. 05:38.010 --> 05:46.200 So anyways, this is so great that the Gengel risk framework, Chingo Reste framework has handled this 05:46.200 --> 05:46.650 for us. 05:47.010 --> 05:51.960 But what if someone wants to create a post via the API? 05:52.020 --> 05:56.640 Like, you know, right now it's a little bit lame that someone has to, you know, log into the admin 05:56.640 --> 05:59.250 side of things and then, you know, add a post and whatnot. 05:59.310 --> 06:01.530 What if someone wants to do that through the API? 06:01.890 --> 06:04.320 Well, let's go ahead and talk about that in the next lecture.