What is Django?

Django is a full-stack python web framework that helps build high-end web applications. It follows M.V.T(Model View Template) design pattern (similar to MVC) for building apps. It comes with a built-in ORM so that you don't have to install or use a third-party library like SQL Alchemy. It also comes with a built-in admin panel that helps you in managing various activities.

Let us jump into the installation part.

Prerequisites

In order to use Django Framework, you need Python installed in your system with the pip package.
If you don't have python installed in your system you can follow the steps here.

Steps to install and run Django


Step 1 (Creating a Virtual Environment):

You can install Django directly in your system but the best practice is to create a virtual environment for your project and install Django in that virtual environment. For that, you need to run the following command in the command prompt.

python -m venv "name of your virtual environment"

or

python3 -m venv "name of your virtual environment"

depending upon the python version you're using.

(Please note you must add the python path to your systems environment variables to directly run this command into the command prompt.)

To know how to add the path to your environment variables you can click here.

After creating the virtual environment you have to activate the virtual environment. For that navigate to your virtual environment folder in cmd and activate it by running the following command:

venv/Scripts/activate


Step 2 (Installing Django):

Then in your command prompt and run the following command:

pip install Django

In some cases, you can run this command if the above command doesn't work:

pip3 install Django

You can also specify the Django version you're willing to install by just providing the version number with the prefix "==". For example:

pip install django==3.10


Step 3 (Creating your Django Project):

After the successful installation you will create your Django project with the following command:

django-admin startproject "name of your project"

This will create a project folder with the required files.

Step 4 (Creating your app):

Navigate to your project folder and run the following command:

python manage.py startapp "your app name"

With this, your app folder will be created with the necessary files.

Django also comes with inbuilt database tables.

Step 5 (Migration and running app):

Go to the settings.py file located in your project folder and add the name of your app under the installed apps section.

To add the default tables to your database run the following command:

python manage.py makemigrations

and 

python manage.py migrate

this will add all the tables to your current database. By default, Django is configured with SQLite database which will be created automatically after the migration process. You may use other databases like MySQL, Postgress, etc. You can change the configuration in the database section in the settings.py file.

After all of this, it's finally time to run our app. For that your need to run the following command:

python manage.py runserver

will give you a port number you access through your browser. The default port for Django is

127.0.0.1:8000

And that's it you're Django app is running successfully.

Thanks for reading, stay tuned for more information. Subscribe to our youtube channel and follow us on social media.