Setting Up Django and Installing Required Packages
Set up a Django project with all the support of Django REST JWT authentication.
Project setup
You aren’t required to install anything to run Django projects on the Educative platform. Instead, a project with all the needed packages is ready and set up for you so that you can focus on the lessons. You just click the “Run” button, and it will run on your browser. However, if there is an error and the project stops running, you’ll have to run it using the manual terminal commands.
For this reason, you might want to know how to set up the project locally on your machine while working on your project. Here is how to do that.
Step 1. Creating a project directory
The first step is to create a directory where your Django project will reside. In your terminal, type this command to create a directory named minicourse
:
mkdir minicourse
Then enter the directory:
cd minicourse
Step 2. Creating and activating the virtual environment
A virtual environment acts like a workspace and is where all the required dependencies for a specific Python project are stored to prevent dependencies conflicting with other Python projects. To create it, type this command in the terminal:
python -m venv .venv
The command above creates a venv virtual environment with the name .venv
, making the directory a hidden one.
Now, we can activate it.
Windows command:
.venv\Scripts\activate.bat
Linux command:
source .venv/bin/activate
Step 3. Installing required packages
You will need to install the following packages:
-
django
: The Django framework. -
djangorestframework
: Enables us to create REST APIs in Django. -
djangorestframework-simplejwt
: Provides the JWT authentication backend that can be used in Django REST.
pip install django djangorestframework djangorestframework-simplejwt
Step 4. Creating the Django project and app
Now, let’s create the project:
django-admin startproject demo
Then, change the directory to the project level:
cd demo
Now, create the app:
python manage.py startapp main
Step 5. Configuring the settings
Now, register your app main
and add djangorestframework
in the settings file under INSTALLED_APPS
.
Get hands-on with 1400+ tech skills courses.