Starting on Django and setting up your first Project!

Starting on Django and setting up your first Project!

What is Django?

Django is a free and open source web application framework, written in Python. A web framework is a set of components that helps you to develop websites faster and easier.

It works with a model-view-controller (MVC) architecture. The model layer contains the core data models. The view layer contains the logic for presenting the data to the user. The controller layer contains the logic for handling user input.

Django includes a lot of built-in tools and libraries to help you build websites:

  • A powerful ORM (Object Relational Mapper) that lets you interact with your database without writing SQL
  • A templating engine to help you design your website's front-end
  • A convenient development server
  • A form library

Django is a popular choice for web development because it is easy to learn and use, and it is very scalable.

Setting up your first Django project ...

Before diving into starting your own django project, you should have the following installed in your PC:

  • Python 3.5 or higher
  • Pip (package installer for python)
  • An IDE (PyCharm/VSCode recommended)

Step 1

Create a virtual environment in your local machine. A virtual environment is an isolated Python environment that allows you to install Python packages and their dependencies independently of other Python projects.

  • In the directory you wish to start your project, execute :
$python -m venv venv

$source venv/scripts/activate

  • Line 1 creates a virtual environment called (venv)
  • Line 2 activates your venv file
  • Line 3 shows that your venv is activted

Step 2

Install required Modules from your CLI inside the directory you wish to start your django project. A module is a code library that can be referenced by your project and used to extend the functionality of your application.

(venv)$pip install django
  • This line installs the django framework in your virtual environment created earlier. Note the venv file is activated!

Step 3

Start project with django-admin The django-admin. To know about the various commands django uses, use the django-admin help. Execute this command to list the commands used

  • This line of code lists for you all django-admin commands you can use for your django project Starting a django project is easy, you just need one line of code and you're good to go! To start, execute:
(venv)$django-admin startproject Project
  • This code creates a directory named Project. The Project directory (or name of your choice is where all the magic happens in django).

And that's how you start on your own django project!