Setting Up Your Django Development Environment (Cheat Sheet)

Bhupeshgurav
3 min readMar 21, 2022

Setting up your Django development environment is fairly easy and won’t take much time to start making an application if you get familiar with the commands

Tools required:

Git Bash

python

First, we have to make a directory where we have to store our Django project

mkdir directoryName

eg:

mkdir musicShop

We have to go into that directory

cd directoryName

eg:

cd musicShop

Now we have to install our virtual environment

pip install virtualenv

Then we have to name our virtual environment

pyton -m venv nameOfVirtualEnv

eg:

python -m venv virutal

We then have to activate our virtual environment

In GITBASH:

source virtualenvDIR/Scripts/activate

eg:

source virtual/scripts/activate

IN POWERSHELL

./Scripts/activate or sometimes ../Scripts/activate

In MAC

source bin/activate

To deactivate our virtual environment

deactivate

We then Install Django inside our virtual environment after activating the virtual environment:

pip install django

We start a new Django project (a project will have many apps)

django-admin.py startproject projectname

eg: django-admin.py startproject musicShop

django-admin.py startproject projectName

eg:

django-admin.py startproject instrumentsApp

After that move into the projectName directory and if we do ls we can see there is manage.py inside the project so that tells us that we are on the right track

Run the server

python manage.py runserver

After this command if we do localhost:8000 on our browser we will get the django’s starting page.

We need apps in our project created so we create one

python manage.py startapp appName

eg:

python manage.py startapp keyBoards

After the creation of the app, we firstly include our app name in our settings.py file.

Next we will create URLs and views for our project.

There will be two urls.py files that we will work with. one is generated when we start a project but it needs to be modified and then we need to create another urls.py file in the new app that we created.

The original urls.py file will look like this

we have to import include and then create a path with the new app

Then we create a new urls.py file in the app keyboards

we will create a templates folder and in that we will add a home.html file and we will create urls for that and views for that file.

We will output hello World on the screen home.html file will look something like this

Finally we have set up all the things and we output Hello World on the screen.

Django comes with a database which we have to migrate it at the start. Basically, we make migrations and then migrate

python manage.py migrate

We have to create an admin user to access the Django admin panel

python manage.py createsuperuser

We can use admin panel now where we can do the database stuff.

I will cover the database side of the django in the next article.

Thank you for reading the article. If you like the article please leave an upvote. Cheers!!

--

--

Bhupeshgurav

Computer Science and Business Engineering Student. Sharing my knowledge as publicly as possible.