- Our main goal is to use django to create a project.
- Since, django is a python framework, we need to install python to run it.
- However, there are 2 major versions of python available - python 2 and python 3.
- We're going to use python 3 since it's the latest version available and is way better than python 2.
- Pip is the package manager for python, we use pip to install python programs so we don't have to download, configure and install it ourselves.
- Managing python versions (2 and 3) is a bit tedious, so we're going to use virtualenv.
- Virtualenv will help us create isolated environment for our django project so we can set which python version we're going to use and not worry about anything at all. There are many other benefits of using it which you'll see later.
sudo apt-get install python3
sudo apt-get install pip3
Since django is a python framework, it's best to install it using pip:
pip3 install django
Installing django should automatically install the command line tool called "django-admin."
Next, we're going to use django-admin
to create our django project:
django-admin startproject [project-name]
Enter your project by using cd
:
cd [project-name]
Virtual environment isolates our project. It helps us select a version of python and not worry about it afterwards.
virtualenv [name] -p /usr/bin/python3
Make sure you cd
into your project before running the command.
source [name]/bin/activate
python manage.py runserver
deactivate