Hello Guys 🙂

Today’s I’m Starting my New Django Series. I have targeted my Django series to the complete beginner developer who wants to learn Django web development. In this blog, I’m going to explore all the basic knowledge of Django.

By the end of this blog, you will able to create your own Django project

Why Django?

Django is a powerful and free high-level web framework which is written in python language which is used by millions of developer worldwide. Django encourages rapid development, clean and pragmatic design. Django is popular worldwide due to its friendliness to both beginner and advanced developers. Django provides a lot of tools and functionalities that make easier to developers during the development of the system like security, session, routing, templates, database access etc.

A web framework is a set of component that provides the standard and relevant way to develop a website fast and easily. Almost all the website needs the same basic functionality: the ability to connect to the database, set routing, handle Security of the system and so on. So, rather creating all these from scratch some developers had created a platform or boilerplate to start your project which is called a Web framework. Some other popular web frameworks are Flask of python, Rails in Ruby and Vue.js of JavaScript.

Popular Sites Using Django

Django is popular WorldWide. There is a lot of large Company who used the Django to build their system. Here I have listed the top 10 Company that used the Django to build their system.

1. Instagram
2. Youtube
3. Spotify
4. Dropbox
5. Disqus
6. BitBucket

Initial Set-Up

In this Section, We will cover the Initial Setup that needs to be done to start the Django project. We will cover how to properly configure your computer to properly run the Django project on your system. Here We will discuss Virtualenv, git and text editor.

Installing Python

Django is a web framework of python so your computer should have python installed. You must have python3 to run the Django project.

Installing Python on Mac

To check if python 3 is already installed or not in your Mac you can use the following command

$ python3 --version

If you get the result 3.7.x then you are a good track. However, sometimes we get an error message so we need to install python 3 directly.

To install python on your Mac, You need to Install Apple’S XCODE package. So run, the following command to install the Xcode Package.

$ Xcode-select -Install 

Next, Install the package Manager Homebrew via a longish command below

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/\
install/master/install)"

To verify, Homebrew Installed properly in your system hit the following commands

$ brew doctor
Your system is ready to brew

And now install the latest version of python, run the following command to install the latest version of python

$ brew install python3 

Now let confirm whether the latest version of Python has been installed or Not.

$ Python3 --version
Python 3.7.0

To run the python3 Interactive shell hit python3 in your command line.

$ python3
Type "help", "copyright", "credits" or "license" for more information.
>>>

Installing python3 on Window

Python is not pre-installed on the window like Mac and Ubuntu, however, you can check the if any version is there in your system. To check whether python installed or not go to command-line tool and type the command below

python --version
python 3.7.0

If you see the result above then you system already contained the python3 package.i

If you don’t see the result above the go to the download package of the official python website.
After Installing the package make sure to Add Python to PATH option, which let you use python directly from the command line.

After python installed, run the following command to test whether the python3 installed properly or not.

python --version
python 3.7.0

If you see the above message,
Congratulations, Python3 has been successfully installed on your device.

Installing python3 on Ubuntu

For this tutorial, I will use ubuntu 18.04 as an example, Ubuntu 18.04 come with python and python 3 installed we can test the version checking through the terminal

Installing Virtualenv

We are going to use pip, a tool to manage and install Python packages, to install Virtualenv.

Let’s start by installing pip in your machine. To install pip type the following command on your terminal.

$ sudo apt-get install python3-pip

Now Installing the Virtualenv in your Machine type the following command in your terminal.

sudo pip3 install virtualenv 

virtualenv is a tool to create isolated Python environments. virtualenv creates a folder which contains all the necessary executables to use the packages that a Python project would need.

For every Django project, you need a Virtualenv.Virtualenv works as a sandbox for a Django project. You can install and uninstall packages without breaking the problem in your Django project.

After Completing the Installation, I have created a folder called Django project.

This folder is a high-level folder that contains all the files and directory related to our project djangoproject.

Let’s start by creating the virtualenv inside our project and install Django.

Inside our project folder run the following command

python3 -m virtualenv venv 

Now, our virtualenv has been created. After creating the Virtualenv we need to start our Virtualenv. To start the Virtualenv run the following command.

We can also deactivate the virtualenv. To deactivate the virtualenv run the following command.

We have Venv activated, now run the following command to install Django

$ pip install django 

Now, We are ready to Start Django Projects.

Starting A New Projects

Now, To create the Django project run the following Commands.

django-admin startproject myproject

After we run the above command, it will create the based folder structure for the Django project.

our initial project structure consists of the following six files.

manage.py: It is a shortcut tool to Django-admin command-line utility.

__init__.py: this empty file tells python that this folder is a python package.

asgi.py: is a spiritual successor to WSGI, intended to provide a standard interface between async-capable Python web servers, frameworks, and applications.

Setting.py: this file contains all the project configurations.

urls.py: this file is responsible for mapping the route and path in the projects.

wsgi.py: this is a simple gateway interface for deployments.

Django comes with a built-in web server for local development. it is very convenient during development. so we don’t have to install any run the project. We can test it by executing the following Commands

python manage.py runserver

Now you can visit http:.//127.0.0.1:8000 in your browser. You can see the following images.