In this tutorial, I will explain in details step by step on how to get started with django by creating a django project. There are two important installations you need make before you can set up Django on your local device. I will split the tutorial into three sections.
- Python installation
- Visual studio IDE installation
- Django setup
If you have installed python on your local device you can skip this process. If not visit https://www.python.org/downloads/ to download the latest version for your window version. Click on download to download the latest version of python. After download, run the .exe file to install it.
Now you have the latest version of python install on your system but there is still one more thing to do before you can access it on the terminal.
Follow these steps to setup your environment variable
a. Type ‘’env’’ on the window search, click on “edit the system environmental variable”
b. Click on edit variable
c. On the user variable slot double click on path and click new button
d. Click on new and copy and paste python path from your system (C:\Users\PC NAME\AppData\Local\Programs\Python). Please make sure you put the right path, as this is just a guide.
Now, to test if your environmental variable is properly set, open your command prompt and type “python –version”. It will display the latest version of python on your system. This shows that the environment variable has been properly configured
2. VISUAL STUDIO INSTALLATION
In this tutorial we will be using visual studio code ide for the django project. There are other ide’s but vs code is relatively easy to set up while working with django.
Visit https://code.visualstudio.com/ and click on download for windows (You can also download for other operating systems). After successful download run and lunch vs code.
3. DJANGO SET UP
Now that we have completed all necessary installations, the next stage is to set up our django .
Create a folder on your desktop (or any other memory location) and name it first-django-project.
Open your vs code you previously installed. Minimized it, then drag and drop “first-django-project” folder you initially created.
At the top menu hover on the three dot(…) close to run button, then click on new terminal. –this will create a terminal for you (Please if your default shell is power shell change it to command prompt).
On the terminal run this command “python –m venv myvenv” to create a virtual environment for the project as shown in the image below
NOTE: if you do not have virtual environment install on your system, open your command prompt and run “pip install virtualenv” . This will install latest version of virtual environment on your system
This will create myvenv folder in your project root folder. To get the virtual environment to work , we need to activate it. To do this just type on the terminal myvenv\scripts\activate and click enter. You will notice that the path has change as shown in the image above. This shows that it has been activated
To install django into your environment you need to run “pip install django” to get the latest version of django install. (Make sure you have internet connections as this will need some resources online)
After successful django installation, you need to create a django project. To do this run this command on your terminal “django-admin startproject myproject”. On your root folder, you will see a new folder named myproject . This comfirm that your project has been created. Now you need to move from the current folder to myproject folder, on the terminal run “cd myproject”. You are now in the myproject folder.
The project has been created but it is just static files, to make it a bit dynamic, let us add database to it. Run “python manage.py migrate” this will create a database using default sqlite database as shown below
Finally, to get the server running run this command “python manage.py runserver”. This will get the server running on http://127.0.0.1:8000/. Copy and paste the url to browser of your choice, this will display the image below
Hurray! That is it. You have successfully set up django on your localhost
In this tutorial you have learn how to install python and vs code IDE on your window system. You also learnt how to set up and run django project in localhost. I hope this has spark interest in you to pick up django framework. Do drop a comment as am willing to hear from you.