This is a blog series about Django from the very basics
Installing & initialising a project
Django is a really powerful Python-based web framework with the philosophy
batteries included. It means it gives you everything you need to build a full-stack web application. Django's Tag line is
The web framework for perfectionists with deadlines. It's because it allows you to create professional-grade web apps very quickly.
However, learning it may seem a bit complex, but believe me, it is not. And to help with that, I'm writing this blog series.
So let's start from the very basics, installation & initialising a project
Installing Django is pretty straightforward. You just need to use pip to install Django. However, it's always recommended to use a virtual environment for a project. So we will start by creating a virtual environment.
python -m venv venv
This will create a virtual environment in the
venv folder. To use this environment, we need to activate it. Activating it is different in Windows, Linux & MacOS.
Bash Shell (Linux)
Fish Shell (Linux)
After activating the virtual environment, we can install Django using pip.
pip install Django
Of this, we have successfully installed Django on our systems. So what are we waiting for? Let's start a project
Initialising a project
To start a project, we will use the
django-admin command. It will help us generate the boilerplate code.
django-admin startproject <projectname>
django-admin startproject triviaquiz
Now to organise our code, we divide our Django web app into several smaller sub-apps. To create a sub-app, we will again use the
django-admin startapp <app_name>
django-admin startapp quiz
This will create a new folder with several other files like models.py, views.py, admin.py etc.
You can try exploring all these files yourself as Django provides comments in the boilerplate code for easy understanding.
However, I will also explain each of them in detail in my next blog.
Running the project
To run the project, we will use the following command:
python manage.py runserver
This will start the server with your project at http://127.0.0.1:8000.
And by going to this url, you will a default Django page like this:
If you are seeing this, then congrats, you have successfully set up & started your project.
In the next blog, I will explain all the different Django files in detail. Stay Tuned
Follow my journey on Twitter: @notnotrachit
Did you find this article valuable?
Support Rachit Khurana by becoming a sponsor. Any amount is appreciated!