Codementor Events

Creating Our First Django Project

Published Aug 03, 2019
Creating Our First Django Project

Introduction

Hi Everyone... I came across so many queries like where to start, how to start Django etc....
So, Here is the basic introduction and setting up of a new project in django.

What is Django

It is one of the frameworks to build web applications, while others being flask, pyramid, web2py etc..
It came as an international project in 2003,but released publicly on 21july 2005.
It is free & open source web framework to develop web applications.
It's main goals are simplicity, flexibility, reliability and scalability.
It is written in Python language.
It follows MVT (Model - View - Template) Design pattern.It is maintained by the Django Software Foundation(DSF).

Features

Security :
Django takes security very seriously and help developers to avoid many common security mistakes.
Fully Loaded :
Django includes various modules and libraries.
Scalability :
Based on the requirement django can easily switch from small to large scale applications.
Versatile :
It allows us to build applications on different domains (Small & Big applications).

Installation of Django

To install Django, Visit to official webpage that is django official documentation and download django by clicking on the download section, Here, you will see various options to download django.
In this tutorial, we are installing django in windows operating system

pip install django==version

Version --> Give version number here(pip install django == 1.11.7).
Type this command in your command prompt and press enter and django will start downloading.Be sure that python is already installed in your system.

Use py -m django --version to check the django version
djangoversion.png

Django Project

In previous topic we have installed Django successfully, Here we will learn step by step process to create a django project.

 django-admin startproject myproject

This command will create the project, myproject is the name of the project

tree /F

It will give the structure of the myproject
treeoffirst.png

manage.py
It is a command line utility which allows us to interact with the project in various ways.
init.py
It's an empty file that signals the folder is a package
Settings.py
It's a file that contains all settings of the project that allow for a running website and configuration of database.
urls.py
In this we can place URL patterns, which are used for routing pages for particular path.
wsgi.py
It means web server gateway interface, and it contains all the wsgi settings.

Next we can run the server, all the applications should be hosted on some server, that server is responsible to provide the environment to run our web application.
Django has it's own internal server, we don't need to install anything.

py manage.py runserver

server.png

Then enter the link http://127.0.0.1:8000/ in browser and check the output
Django output.png
If the output is shows like this you are all set.

We can change the IP Address also , ip address is like unique identifier.

py manage.py runserver 5555

and then check the output http://127.0.0.1:5555/
change ip output.png

This is all you have to know to start with Django...

Discover and read more posts from Sadhana Reddy
get started