How to set up Django

Step1:

As we know that django is framework of python so our system must have python. To check python is installed you must type below commands on your command prompt or terminal.

Command: python –version

django-setup1

If your system does not have Python you must install it from their official website(https://www.python.org/downloads/). During installation time you must ensure to check the box “Add Python to PATH”.

Step 2:

Create a Virtual Environment in that folder in which you want to make the project for example I have a folder test in which I want to create a project so I can create a virtual environment in this folder

Go to that folder where it is placed and install the virtual environment

Command: pip install virtualenv

pip install vitrualenv

 After installing the virtual environment we create a virtual environment in that folder

Command: virtualenv venv(name of virtual environment)

virtualenv venv

Then we activate that virtual environment(venv)

After that we install django

Command: venv\Scripts\activate

venv-activate

Command: pip install Django

pip install django

If you want to know Django install correctly you must type below

Command: Django-admin --version

django-admin--version

For creating Django projects you must write the below command

Command: Django-admin start project basic (name of projects)

django-admin startproject basic

This will create a directory structure like this:

Django project Structure

manage.py: This defines utility for interacting with the project.

urls.py: It manages all the routing of the project.

setting.py: It sets all the configuration which is needed in the project.

For running the development server you must go to the project folder(basic)

Command: cd basic (project name)

djnago project setup

And start the Django development server with the below command

Command: python manage.py runserver

python manage,py runserver

Then copy URL in the browser and go to http://127.0.0.1:8000/ to see the default Django welcome page which looks like this

Django Project

This shows our Django has been successfully installed in our project.

You may also like...