Hello guys, welcome to LearnVern.
What did we see in the last topic?
We saw how the project & application was created, we had followed some steps with cmd, how we had made the project & application.
We had also understood its file folder structure in the last Django video.
Now today, we will see how to work with the Django Admin Panel.
Django has an admin panel, okay, how to work with the facility provided by Django, how to set up, I’ll tell you everything step by step again.
Okay.
But, first of all, the previous video about creating a project & application is compulsory because we are going to follow the same steps we followed in the last video.
Right?
So you need to know those, okay.
To begin with, let’s know what the Django Admin Panel is.
Django Admin Panel is a Ready to Use User Interface.
Okay.
Which is already provided by Django.
That means, you don’t need to design a UI.
Okay.
Django provides you with an Admin Panel wherein there are all the functionalities an admin should have.
Meaning you can give permission to which user through which particular admin panel, you have to work with which table, you can access any table you want, you have to give permission to any user that this particular user has to work with certain permissions only.That the 2nd user has to work with certain permissions only.
You can decide that from here.
Meaning, you can provide permission to a particular user from a particular panel or you can access any table to do your work or you can also grant a set of permissions so that the user could work within certain constraints. This means that you could decide which permissions you want to give and to whom. The first user would work with certain permissions while the second user would have certain permissions.
Django itself provides an Admin Panel and it is very easy to set it up as well.
Okay?
And the Django Admin Panel is a very important part of this Django.
When you are making your project, there is an Admin Site.
We will work along with the Admin Site by using the Django Admin Panel.
So guys, this Django Admin Panel is a very useful thing in Django through which we can manage our users.
Right? Clear?
You can create your own Custom Admin Panels as well but you’ll have to add your functionality while here, in this, Django is providing you by adding all the functionalities in this particular Admin Panel.
Okay? Right?
So we have to keep these things in mind.
Now let’s see how to set them up step by step.
Right?
First of all, what do you have to do?
You have to create a Project.
Like I told you in the beginning, those of you who haven’t watched previous videos in which I showed you Application & Project with configuration, please watch those videos first.
Because all of these videos are based on that video only.
Okay?
So what do you have to do first of all?
You have to create a Project for Django.
Right?
After that Django project, you have to create a Django Application.
Okay?
Now, this third point is new for you so I'll show that to you practically.
Also don’t worry, I am going to explain every step to you over here.
Alright?
Now you have to Install Django’s Application in Django’s Project.
Okay?
And then what you have to do is, there is a urls.py file in your project, which I told you about in the last video that there is a urls.py file available.
Right?
So you have to include your application in that file.
Meaning you have to include its URL.
Second, you have to create a new file in Application and name it urls.py
This file won’t be available in your application, you’ll have to create it.
Okay?
I’ll show you practically how you have to make it.
Right?
Clear?
First, I’ll tell you how to follow these 5 steps.
Okay?
Let’s go.
Okay guys.
So I have made a folder here named Django Admin Panel, right?
Now you have to go inside that folder, and what do you have to write here?
CMD.
I had told this to you in the last video as well.
Right?
As soon as you write CMD, this will open up here.
Clear?
Now, this CMD opened up here.
What is the next first thing that we have to do?
First of all, we have to create a project, right?
So how do we create a project?
Let’s do it.
Okay?
Come on…
First of all, what do you have to write here?
Python - m venv myvenv.
This command was for what?
This command was for creating our virtual environment.
Okay?
So just as I press Enter, a folder has been made on the backside.
Right?
Now what do we have to do with our Virtual Environment?
We have to Activate it.
What do we have to do?
We have to activate it.
How will we activate it?
My venv, meaning our virtual environment’s name, then Scripts, then Activate.
So what will happen? Our Virtual Environment will get activated.
How will we know that?
Can you see this here?
You can learn about Virtual Environment due to this particular thing, whether it is activated or not.
If this is not showing here, it means that your virtual environment is not activated.
If this is being seen, then your virtual environment has been activated.
Okay?
Now what you have to do is, you have to install Django here.
How will you do that?
Pip Install Django.
As soon as you fire your command, your installation process is started.
Right?
Okay?
So this is installed here.
Now what do we have to do here?
We have to create the Django Project first of all.
How will we do it?
Django - admin startproject, then project’s name.
Okay?
You can name the project anything.
I have kept the project name as project only.
Right?
You have to put a fullstop after the space.
I told you the reason for the same in the last video, so please watch the last video once.
Just as I press Enter, you can see that 2 files are made on the backside, right?
Now what do we have to do?
We have to make an application.
How will we make it?
Python manage.py startapp and then application name.
Here too you can name your application anything you want.
I have named it App only to make it easier for you to understand.
Okay?
Just as I press Enter, my app folder has been made here on the backside as well.
So what happened here is that only our Django has been installed, our project is made as well as our app is also created.
Right?
Clear?
Now what is the third point?
Install Application in Django project. Okay?
How do we have to do it?
First of all, what do we have to do?
We have to open our VS code.
How will you open VS code?
Code space dot.
Okay?
Right?
Our VS code is open, right?
Now here you have to go to the Settings dot py file.
Here if you go a little bit down, you can see Installed Apps.
Here, after pressing Enter, you have to write in single inverted commas, the name of the app, meaning, the name with which you have made the Django application, you have to write that name.
I have made a folder named App so I wrote the name App and then comma.
Right? Clear?
So what is this?
Application installed in Django Project.
Okay?
I have written this hint so that you can understand it properly.
Right? Clear?
Now what you have to do is, Include, our 4th point, what is it?
Include application url in Django Project urls.py file.
That means that in our Django file project, there is a file named urls.py in which you have to include your application url.
How will you do that?
Here you can see your urls.py file in your project.
I opened it.
You have to go downwards here.
Then you have to import one thing near the path, which is include, right?
Clear?
If any of you is not able to get the suggestions, then in VS Code, go to Help, in that go to Welcome, right?
Here, whichever functionality, perhaps python or some other language, you have to install that here.
If anyone can’t see the python extension, what do you have to do?
You have to go here…here is your python extension.
You have to install it here, right?
As soon as it will get installed, your VS Code will restart once.
Okay?
After it restarts, you will get python’s functionality in the VS code.
Okay?
You will have to restart your VS code once.
Alright?
Okay.
So I included it here.
Now what you have to do is, go to path, our first parameter, our double inverted commas, you have to leave it blank.
Why do you have to leave it blank?
Because your request will first be in your project, and then it will go to your app.
I had explained this Django Architecture to you, right? During Introduction to Django.
So you have to see that here.
Okay?
Then write Include, and then in single inverted commas, first you have to write your app name.
What is my app name?
It is app.urls. You have to write that here.
Okay?
What will happen when you write that here?
This will be your app url, that is your application url included in Django project url.
Okay?
So what you did here is, that you included your application url in your Django project.
Okay?
Now what do you have to do?
What is the last point?
Create one file in Application and name it urls.py file.
Okay?
So you have to go back to VS Code, right click on your app folder, New File, and what do you have to name the file?
Urls.py.
Just as you press Enter, your file is ready.
Right?
And then what you have to do is, from the urls.py file of the project, you have to copy this portion, right, and paste it here and then remove this part.
Okay?
Right? Clear?
Is this much clear to all?
Okay?
So what did we see so far?
We saw how to install an application in a project, how you have to include your application in urls.py file, and how you have to create urls.py in your application.
Right?
Now we will move forward, okay?
Next up, what do we have to do?
We have to Migrate Django Tables.
Okay?
Essentially, Django has 10 tables of its own.
Okay?
It belongs by default so it is compulsory to migrate them.
Understood?
So what does Migrate mean?
Your database means the database of Django, the tables of Django are scanned into the database, it commits under the database.
We had used the commit function in Python with database connectivity.
Right?
So in one way in Django, if any table has to commit in the database, then you have to use this command - python manage.py migrate.
You have to fire that command, okay?
So what this command does is, it migrates all your Django tables in your particular database.
Got it?
What happens is, whatever necessary tables are there in the Admin Panel, through which your Admin Panel is going to work.
So it creates those particular tables in the database.
Okay?
Database is provided by Django itself.
Let’s see with the practicals, how this command is fired.
Open CMD. okay?
Virtual Environment should be compulsorily opened.
Then you have to fire your command which is Python manage.py migrate.
Okay?
As soon as you press Enter, you can see this…these are the Django files.
And if you see behind in the project, a db.sqlite3 file has been created.
Which means that Django has created a database file.
Alright?
You have to do this compulsorily because then only your admin panel will start.
Without this table, you cannot access your admin panel.
Okay? Right?
So we migrated.
Now we will create a Super User.
But first of all, what is Super User?
Super User is 1 type of main Admin who has all the authorities, all the permissions is called Super User.
So what you have to do is, whenever you open the Admin Panel, okay…
To open the Admin Panel, you have to Login first.
I’ll show you practically how we will get it.
We did the migration.
Now what do you have to do?
You have to run the Python manage.py server.
What do you have to do?
You have to run the server.
So what is Django?
It is a web based framework which runs on a particular server.
Did you see here that the server got run and it provided us with a url.
Can you see this url?
You have to copy this url, okay?
Press Ctrl + C only once, because when you press Ctrl + C a second time, it will stop your server.
Right?
Keep this thing in mind, okay?
And you have to go to the browser, go here, and paste this.
When you press Enter, it will show you that Django has been installed successfully.
But if you want to open the Admin Panel, then how will you do it?
Slash, then write Admin.
Just as you press Press Enter, this interface will open up where it will ask me username & password.
You will have to create this particular thing.
Right now, you cannot enter with any user, okay?
It will ask you to create a username.
Your username and password is not yet created or corrected, you have to create it.
First of all, I’ll explain how to create it.
Right?
Now what you have to do is, you have to create a Super User.
Create what? A super user.
How will you create a Super User?
First and foremost, without Super User, you cannot access the Admin Panel.
I showed that to you practically.
To create a super user, you will have to fire this command which is -
Python manage.py createsuperuser.
You have to write this createsuperuser combined, without any space.
Okay?
How will we do it?
Let’s go to CMD, right?
Firstly, we’ll stop the server.
To stop the server, press Ctrl + C, right?
And you have to write a command that is Python manage.py createsuperuser.
Okay?
Press Enter and it will immediately ask you for credentials.
Right?
If you want to keep the username Admin, okay, or you want to put your PC name, you have to keep it blank.
See, here it is mentioned ‘leave blank to use admin’.
Okay?
If you want to name it something else, you can type it here and if you keep your PC’s name, then leave it blank.
The second credential will be an email address.
Entering the email is mandatory as well but there are certain validations in it.
You must mandatorily use @ in the Email ID, okay?
This is the first framework which gives validation under CMD.
Right?
It doesn’t matter even if your Email ID is fake.
Suppose I use s@gmail.com
Okay?
Now it will ask you for your password.
It is compulsory to write a password and it has its validations as well.
Your password should not match your username.
Okay?
Whatever name you have kept, should not be included in the password.
Your password is supposed to be of 8 characters.
Okay?
I have written a password but you can’t see that in CMD.
Remember that also.
As soon as I pressed Enter, what did it show?
Superuser created successfully.
Right?
So now you can login into your Django Admin Panel.
After doing all of this, you have to once again run your server.
Okay?
Go to Browser.
Write down whatever name you had entered in CMD and the password that you have entered.
As you press Enter, you will be in your Django Admin Panel which has opened up.
Okay?
So this is the Admin Panel in which there are users…
What is our present user?
It is Admin with this Email ID and it is Staff Status, which means it has all the permissions available.
Right? Clear?
So this is our Django Admin Panel through which we can access everything such as User management, Models Access, etc.
Okay?
If you have any queries or comments, click the discussion button below the video and post there. This way, you will be able to connect to fellow learners and discuss the course. Also, Our Team will try to solve your query.
Now when I meet you in the next video, we will see how to add models in admin panel and how to create the models.
Okay, right?
Let’s meet in the next video where we will see models in the Admin panel.
Share a personalized message with your friends.