So I know this was a little disappointing.
We got to the place where we could show our API.
But there's nothing there yet.
Well, we've got to throw some things in the database.
So I think the first and easiest way to do this is to create a super user and use the admen portion
of Django to our advantage.
So let's go ahead to move back to our terminal, do a control, see to stop the server and let's go
ahead and make a super user for our project.
So and before we do this, we've got to make sure I think we've already migrated our date database.
But let's make sure Python for me, I've got to make sure I have Python three managed up high migrate
and.
Yep, we're all good to go, Kane.
So with this, I'm going to say Python three managed that pie and now I want to create super user.
All one word.
So I'm going to go ahead and just use the name zappy code here.
Feel free to use whatever you'd like.
I'm not going to be using an e-mail with this and I'm just going to use a simple password.
A, B, C, D, one, two, three, four, abc d, one, two, three, four.
Awesome.
It is very common.
Sure you want to use this?
Yes, I do.
OK.
So with that in place, let's go ahead and run the server again.
OK.
Now that's up and running in a new tab.
I'm going to go to a copy that you are l here so that we have it to go to slash admen.
I'm going to log in with my super user, which for me is zappy code might be different for you.
And I'm going to give that a, b, c, d, one, two, three, four, password.
OK, so now that I'm in here, I'll be able to see whatever we have in the database and save things
in there.
But you'll notice we don't have anything showing up for our particular post.
So remember, if you remember this from Django, we've got to go back to this.
Admen dot py file inside of the post app.
And we need to register our classes with the admin.
So we're gonna go ahead and bring in our two models.
You're going to say from models import.
I'm going to bring in post and vote.
Then I just simply need to register these.
I'm going to say admen that site.
Register.
And we'll go ahead and pass in first the post and then we'll copy this line and do it again for the
vote.
Thanks.
So if we save this file and then come back to our Admon and reload, look at that post and votes show
up.
Now our API is supposed to show post objects, so let's go ahead and make a post object.
I'm going to say posts add post the title here is going to be.
A cool Web site to learn.
Code look at me shamelessly promoting my own Web site here.
So this is going to go to zappy code dot com.
And with Django, you, Earl Fields, you have to make sure it's HTP or HTP s with the colon slash all
that jazz.
And we have to pick who who it is.
That's Posadas.
We only have one user right now, so I'm going to pick zappy code, but I'll go ahead and hit save.
So now we can see in the admin side of things that we have an object and if we go back to our API,
I'm going to reload this.
Look at that.
The API is up and running.
We are listing out all the post objects that are there, so let's go ahead and make a new one.
OK, let's go ahead and add a post here.
I'm gonna say a great way to make an API and I'm going to go grab the jingo rest framework.
You I'll post this in here.
Again, this is a zappy code, so I'm going to save this.
Reload the API.
Isn't this awesome?
This is so cool.
And we can do this through the browser or in the terminal here.
If I do a control C and stop, I can say Kerl copy the URL that we have here.
Paste this in.
And now I forgot.
We have to be running the server, so let me run the server in a new tab here in a different terminal
window.
I'm going to say Kerl and then that you are all looking at it brings back the Jason for that particular
API call.
Isn't that great.
This is so cool that we have this up and running now.
Something that I want to talk about this because this is a really big dear deal here is that the Jango
Rest Framework framework makes it so that if we're going to list out some API, for example, to go
to our views here, where we list out all the posts, this whole class base view magically makes it
so that if I visit this, you are in a browser, it will detect that I'm with a browser and it will
give me this really nice detailed page that says, hey, this you are real here, accepts get head and
option requests.
It's going to be Jason objects and it lists shows you a preview.
If you want to show just the raw data, you can go to Jason, which you'll notice that you are all for.
This is, you know, has the little question mark here format equal to Jason.
So this is all baked in.
It can come back just as simple as, you know, the Jason that you see here.
Or you can get this full h t mail layout showing everything inside of here, OK?
So if you go on options, it shows a little bit more details about what things this API can spit back.
But honestly, if if you're not really diving deep into the framework, there's there's not tons of
great information here.
So anyways, this is so great that the Gengel risk framework, Chingo Reste framework has handled this
for us.
But what if someone wants to create a post via the API?
Like, you know, right now it's a little bit lame that someone has to, you know, log into the admin
side of things and then, you know, add a post and whatnot.
What if someone wants to do that through the API?
Well, let's go ahead and talk about that in the next lecture.