Getting Started with Django from Scratch

Getting Started with Django from Scratch

You'll need these prerequisites:

  • Brain

  • Computer (with Windows in it)

  • Python-the programming language, PIP

  • Python (optional only for people with passion)

  • Access to clean drinking water, edible food, breathable air, Clothes, body, Doctorate in Computer Science, 30Years of Experience as a 19-year-old or (You need to be a Django Master like me).

  • Browser in your Computer

  • Keyboard

  • Keyboard Switches

  • Keycaps

  • Mouse

  • Mouse Buttons

  • Mouse Pad

  • Electricity

  • Connection to Internet

  • a Life (optional)

  • Power Cord

  • LED Lights (very Important)

  • Learn the Django Docs byheart 3 times (can't be skipped)

Installing Django

Whenever You are Trying to use the Best Web Framework there is a.k.a. Django. Our Project may depend on some certain lower tier packages to run. and sometimes those packages get updated to higher versions that could cause a project already in deployment to crash. and when we do need to Maintain/add a feature to a project already in Production. we need to know all the packages used and their versions. which makes 1 developer working with more than 1 project a nightmare.

PS: I never Have any problem like this because I am the Django Master.

To resolve this possible future issue, we create Virtual environment to develop our project in, and we will use fancy commands to create a requirements.txt file to let our deployment server know what packages are required to run the project.

You need to type python -m venv <virtualenv name> in console of your choice. and
<virtualenv name>/scripts/activate to activate the Virtual Environment. Below is an example for creating a virtual environment in python named "theusernamedvirtualenvironmentnamegoesinhere"

python -m venv theusernamedvirtualenvironmentnamegoesinhere


You should see this sort of screen after you've activated the virtual environment.

You know when the Virtual environment is activated by looking for a (theusernamedvirtualenvironmentnamegoesinhere) in the beginning of each line.

You need to hit pip freeze after activating the virtual env. and it should return blank line, which means no packages have been installed in our environment(virtual)

if there are some package names being returned by pip freeze, recheck if your virtual environment is active.
once you have made sure your virtual environment is active. you can go ahead and download Django with pip:

pip install django

you should see this screen:

after the download is complete, You can do pip freeze and it should show Django, asgiref, sqlparse, tzdata as the packages. You are ready to start your project now.

the command to create a Django project is:

django-admin startproject yourprojectnamegoesinhere .

the "." at last tells Django that the current directory you're in will be your main project folder. if you don't add that . at the end then your project will be made inside of a folder named "yourprojectnamegoesinhere"

then we need to go to the project's main folder and use the following command

py runserver

This command will start the server for us and give us the link to the port where the local server is hosted. below is a figure demonstrating it:

Now, we can see the Actual Web Server if we go to localhost:8000 on our browser of choice. The landing page of empty Django web server Looks like this:

CONGRATULATIONS! You've completed 1/900 Steps of Becoming a Django Master.

In next Blog We'll be creating The Best To-do app anyone's ever seen

Did you find this article valuable?

Support Nischal lamichhane by becoming a sponsor. Any amount is appreciated!