This tutorial is meant for beginners or if you want have a quick view on how to set up Django project
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 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 python download to download the latest version for your operating system. Click on download to download the latest version of python. After download, run the .exe file to install it.
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
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
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 visualstudio.com and click on download for windows (You can also download for other operating systems). After successful download run and lunch vs code.
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
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
In this tutorial you have learnt 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.