Prerequisites and OS Considerations
Welcome back, aliens. My name is I've already and in this video, we'll create our first Django project. But hold on, to work with Django, we have to install Django first. And unfortunately, we don't have a setup here.
Now when you say you want to install Django, of course, you have to be specific with the OS you're working with because for different types of OS, we have a different setup for Django. If you are using a Linux-based OS or if you are using a Mac, they have all more or less the same steps, but in Windows, we have different settings to work with.
Now, in this series, we are going to start with Windows for various reasons. The recording software which we are using works well on Windows, and most of the people are using Windows. I will still suggest you to move from Windows to Linux to enjoy programming, but just to get started, let's start with Windows. Of course, the coding part will remain same, doesn't matter which OS you're working with. So let's get started.
Downloading and Installing Python
First of all, you need a setup. Now, if you want to work with Django, as we mentioned, Django is a web framework for Python. That means if you want to work with Django, you need a Python setup. Now if you have seen my Python series, we have done the Python setup there, and then we have learned so many things, right? So if you have done those things, if you have done the setup, you don't have to install Python again. It's there in your machine. But what if you don't have a Python setup? So that's where you will install it.
Now, when you say you want to install something, there is one little question, which is about the version. Which version are we going for? So for Django, we are going for version 2, to be specific, it is 2.2. Of course, if you are watching this video after some time, you will be having some new versions, but don't worry, at least for 2.x, they will not be having any major updates, so you can just check that on the documentation.
Now, for the Python setup you need, if you want to work with Django 2.2, you need a latest version of Python which is more than 3.4, I guess. So you just have to go to Google, just search for Python download. Go to the website you have to go and click on that.
Now once you come to this website, you can see we have an option of download Python 3.7.3, which will surely work. It is more than 3.4, right? But you have to also check one thing, which is the type of Windows you're working with. Is it a 32-bit OS or is it a 64-bit OS? And based on that you can do the setup. So download the version which you have with you.
So this is a 64-bit OS, and I'm downloading that. So once you've got the setup with you, you just have to go to downloads. You just have to click on the setup which you got downloaded. So you have to make sure if your Windows version is 64, just do that, okay, 64 OS. And then you have to also make sure that you do this, you have to say add Python to your PATH so that you don't have to do that setup later. So just check that and here click on install now. It does take some time.
Verifying Python and Pip Installation
Okay, so it says setup done for Python. Click on close. Now once you've got your Python installed, how do you verify it? Best way, open CMD, and that's your CMD prompt here. Okay, so here we have to check for the Python version. So the way you can do that is by saying python --version. Now it's going to give you the version of Python which you have, which is 3.7.3.
The next thing you need is pip. Now, pip is an installer manager for Python. So when you install Python, you will get pip as well. So just simply say pip and let's check the version of this as well. And it should be 19.1 or 19.0.3, both works. So you can see I have 19.1, the latest version.
Now once you've got Python with you, once you've got pip, we have to also check for Django. Of course, we don't have a Django setup. The way you can verify that is by saying django-admin version. That's how you... that's the Django command you can use. And you can see it says there's no Django available, so of course we have not installed it yet. So we've got Python, we got pip, let's install Django.
Creating a Virtual Environment
Now, you feel... if you install Django here, it will be available for the entire machine. Okay, so what if you want to have a different configuration for Django for different projects? So let's say if you are working with multiple projects, you want to have a different setup for Django there. So just imagine from the entire system, you are creating a space for your projects, which will not be affecting the other projects which you have. And the way you can do that is by installing a virtualenv wrapper. So let's do that.
The command is pip install virtualenvwrapper-win and you just have to say enter. So it will install the virtual environment for you. And that's done. You can see we got this setup.
So once you got this setup for the environment, we have to actually create the environment, because this will not give you the environment. This will just install the wrapper, or the environment wrapper. So we have to create an environment here. The way we do that is by saying mkvirtualenv, space, and you just have to give any name to it. So, I will say test because I'm testing it, and I would say enter. So it does take some time and... so you can see we got our environment.
So what we have done is we have installed Python, and then we have... we have installed a virtual environment, and then we have actually created the environment. So the environment name here is test, a small environment where you can go. And you can also see it says test here. So just before your command, we have test there, which means we are in the environment.
Installing and Verifying Django
Now, once you are in the environment, now we have to install Django. Let's do that. And is it difficult? Of course not. We have a simple command here. So we can simply say pip install Django. I know we are working with command prompt, and some people don't like it, but come on, you are a programmer, right? This is something you should be loving doing. So we have pip install Django and it will install Django for you. Simply press Center... now, based on your internet speed, based on your system speed, it will take some time.
And that's done. You can see it says 'installed Django 2.2'. This is what we wanted. In fact, you can actually check the version now. So you can say django-admin version. So you can see we got... oh, something went wrong here. So we got 2.2. So that's the version which you are working with. Okay.
But what if I open CMD again and if I check, do we have Django available here? And you can see it says Django is not available. So that's the thing. Django is there only in our environment. It's not there for the system. And that's what we want, right? We don't want to disturb the entire system just for our project. So we have the environment where we have Django available.
So we got Python, we got Django, and now let's create our first project.
Creating Your First Django Project
Yes, that will be done using command aitself. Okay, but then how will you do it? No, we can't do that. In a particular project. So what normally I prefer is I keep all my projects in one particular folder. So let's do that. We'll create a folder here. So we'll say mkdir projects. This is where I will have all my projects. So we got a folder which is projects, and let's move to that folder. So I'll say cd projects. Oh, sorry, projects. And now you can see we are in that project. So let's do it. We got a folder and we are into it. And let's create our project here.
But to do that, we have to use a command again. But don't worry, you will get used to it. So we'll say django-admin. So what do I have to do with this thing? You have to say django-admin, and you have to create a project, which is startproject, and I will give a project name. So that's the command, django-admin, and then you have to say startproject and you can give any project name you want. So it seems to be... for telescope we'll let's give a project name as telusko itself. And we'll say enter.
Exploring the Generated Project Files
But before doing enter, let me just go to this projects folder just to see if it is empty or not. So I'm in my C drive, and so in Users we have telusko, let's go there and you can see here we have a projects folder which is empty. And the moment I say enter here, it will create a project for you. Let's go back to the folder and you can see we got the telusko project. Now, what do you think? Will it be empty or not? Let's double click here. And you can see, it's not an empty folder. We have a manage.py file, I don't know why we need this, let's see that later. And then we got a telusko folder in which you have four different files. We'll talk about these things later, you know, what exactly these things are.
But as of now, the important file here is manage.py. To access that manage.py, first of all we will navigate to the project which we have created. So the project name is telusko. So we can see we are in telusko now. And if I say ls... now that's linux. If I say dir, you can see we have a file which is manage.py. So we have this. And then in telusko as well, we have settings file, which is important. We have urls.py. We are building a website, right? So of course in the website you will be having a lot of URLs. So this will be used to handle that. This is something which will be used to deploy your project on the proper server, because when you're working while you're learning stuff, you will not be working on the production server. You'll be working on a development server, the testing server, basically. So we'll be using this. We don't actually use __init__.py, so we'll not talk about that.
Running the Development Server
Okay, so we got our project. We are into that project now, but what next? We have not done any coding as of now, but still you can run the project, this particular project, and you can run this on a... on a private server. Of course you need a server, right?
Django says, "Hey, don't worry. Since you're installing Django, we will also give you a lightweight server." And to access that, we have to say python and we have to use a file which is manage.py we have seen this file before. And then the command we have to use is runserver. And the moment you say enter, you can see you got your server up and running without any errors. It also says some different stuff, we'll talk about that later. In fact, in the theory video we have talked about MVT, right? Which is Model View Template. In model it works with database, right? It handles data, that's why it is giving you those warnings, but as of now, let's ignore them.
What is important is, it says your server started at this IP address. So this is your localhost address, basically. And the port number is 8000. Of course you can change this port number, but I will just go here, I would say 127.0.0.1:8000. And you can see this is your Django homepage. Okay, why are we getting this? Why not our own project data? Because we have not done any coding as of now, and that's why you are seeing this. If you want to experiment, you can simply click on... you can see below we have tutorials, a polling app. Let me just go there. It will show you the steps, how to create a project. You know, I just love documentation part here. So you can follow this documentation just to learn more.
So that's how you do a setup for Python, for Django, and we have created our first project without the coding, of course. So in the next video, we'll write some code and we'll do some experiment here. So I hope you enjoyed this video, let me know in the comments section and do subscribe for further videos. Bye.