Note: This tutorial assumes you are familiar with HTML. If you aren't, don't fret! It's pretty simple to learn. I'll provide samples, but if you are confident, you can just write your own. I'll also be using CSS from the Bulma Library.
The very first thing we'll need is an installation of Python. If you are on Windows or MacOS, grab the installer from the official Python website and proceed with the installation. If you are on Linux (Ubuntu, Fedora, Arch, Raspberry Pi OS, etc), you should already have some version of Python installed.
Once we have some version of Python, we can verify by running the following command:
<python command here> --version
I am writing this tutorial on Linux, so I'll run python3 --version
. On Windows, the Python
command may be py
or py -3
, and on MacOS, the command may be python
.
This should give us an output of Python 3.xx.xx
(just make sure that the Python version is
around 3.11)
Once you have Python installed, check to see if PIP, the Python
package manager, is installed. Pip will let us use other people's libraries (which just means their existing
code) with our own. On Linux you should be able to run
pip3 --version
, or if that fails, pip --version
. If Python is installed correctly,
You should see something like the following:
pip 23.x.xx from /usr/lib/python3/dist-packages/pip (python 3.xx)
On Windows and Mac OS, you may need to run the following instead:
<python command here> -m pip --version
While I could start the tutorial here, it is usually best practice to install necessary Python libraries
locally in a virtual environment. What does that mean? Now that your computer has a installation of Python,
using pip to install libraries will install them globally, meaning your entire computer. While this isn't
necessarily a bad thing, most of the time, we just need libraries for one project. That's where virtual
environments come in. We can create a virtual environment for our project, and install all our libraries,
there. To do this, we'll use the help of the built-in Python venv
module. Navigate (and/or make
it if it doesn't exist) to the directory (another word for folder) where you store your code projects (I prefer having a
Projects
directory in my home folder). Once you are there, open a terminal (CMD on Windows) in
that directory. Then run the following command to create a virtual environment:
<python command here> -m venv DjangoEnv
Great! Now we have our virtual environment ready. To enter the folder we just made in the terminal, we can run the following command in the terminal:
cd DjangoEnv
This will enter the ByteClubBlog directory created earlier. To activate the virtual environment, run the following:
For Linux/MacOS (bash/zsh):
source bin/activate
For Windows (CMD, for Powershell use activate.ps1 instead):
Scripts\activate.bat
Note: If you need to deactivate the virtual environment, you can run the deactivate
command.
Now that we have our virtual environment activated, we can install Django into it using pip. Run the following commands:
<pip command here> install django
As I'm on Linux, I'll run pip3 install django
. If you are on Windows or MacOS, it'll be
<python command here> -m pip install django
. To verify we've installed django correctly,
run the following:
<python command here> -m django --version
You should receive output confirming you have Django version 4.x
installed.