DEV Community

Cover image for SETTING UP DJANGO PROJECT
Olaoye kunle
Olaoye kunle

Posted on

SETTING UP DJANGO PROJECT

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.

  1. Python installation
  2. Visual studio IDE installation
  3. Django setup

1. PYTHON INSTALLATION

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.

Image description
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

Image description
c. On the user variable slot double click on path and click new button

Image description
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 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

Image description
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)

Image description
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

Image description
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

Image description
Hurray! That is it. You have successfully set up django on your localhost

Conclusion

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.

Top comments (0)