Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
168 views

Why Django Framework ?

Django is a Python-based web framework that allows for quick creation of efficient web applications. It is called a batteries-included framework because it provides built-in features like an admin interface and SQLite3 database. The document discusses Django's architecture, features, benefits, installation process and creating a basic project.

Uploaded by

Ichan Kabir
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
168 views

Why Django Framework ?

Django is a Python-based web framework that allows for quick creation of efficient web applications. It is called a batteries-included framework because it provides built-in features like an admin interface and SQLite3 database. The document discusses Django's architecture, features, benefits, installation process and creating a basic project.

Uploaded by

Ichan Kabir
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

DJANGO

 Django is a Python-based web framework that allows to


quickly create efficient web applications. It is also called
batteries included framework because Django provides
built-in features for everything including Django Admin
Interface, default database – SQLlite3, etc.

Why Django Framework ?


 Django is a rapid web development framework that can be
used to develop fully fleshed web applications in a short
period of time.
 It’s very easy to switch database in Django framework.
 It has built-in admin interface which makes easy to work
with it.
 Django is fully functional framework that requires
nothing else.
 It has thousands of additional packages available.
 It is very scalable.

Django architecture

Django is based on MVT (Model-View-Template) architecture.


MVT is a software design pattern for developing a web
application.

MVT Structure has the following three parts –

Model: Model act as the interface of the data. It is responsible


for maintaining data. It is the logical data structure behind the
entire application and is represented by a database (generally
relational databases such as MySql, Postgres).
View: The View is the user interface — what is seen in the
browser when a website is rendered. It is represented by
HTML/CSS/Javascript and Jinja files.

Template: A template consists of static parts of the desired


HTML output as well as some special syntax describing how
dynamic content will be inserted.

Features of Django

Versatility of Django
Django can build almost any type of website. It can also work
with any client-side framework and can deliver content in any
format such as HTML, JSON, XML etc. Some sites which can
be built using Django are wikis, social networks, new sites etc.

Security
Since Django framework is made for making web development
easy, it has been engineered in such a way that it automatically
do the right things to protect the website. For example, In the
Django framework instead of putting a password in cookies, the
hashed password is stored in it so that it can’t be fetched easily
by hackers.

Scalability
Django web nodes have no stored state, they scale horizontally
– just fire up more of them when you need them. Being able to
do this is the essence of good scalability. Instagram and Disqus
are two Django based products that have millions of active
users, this is taken as an example of the scalability of Django.

Portability
All the codes of the Django framework are written in Python,
which runs on many platforms. Which leads to run Django too
in many platforms such as Linux, Windows and Mac OS.

Installation of Django
Step1: Install pip using (python -m pip install -U pip)
Step2: Install virtual environment using (pip install virtualenv)
Step3: Set virtual environment
1. Create virtual environment using (virtualenv env_site)
2. Change directory to env_site using (cd env_site)
3. Go to Script directory and activate virtual environment
using (cd Script && activate)
Step4: Install Django using (pip install django)
Step5: Return to env_site directory and start project by using
(django-admin startproject geeks_site)
Step6: cd geeks_site
Step7: Start server using (python manage.py runserver)
Step8: http://127.0.0.1:8000/

Benefits of Django Architecture –


 Rapid Development
 Loosely Coupled
 Ease of Modification

Drawbacks of MVC Architecture –


 Too much load on Model Component
 Development Complexity is high
 Two components are controlling View

One should be using Django for web


development in the following cases:
 For developing a Web Application or API Backend
 For Rapid Development of some web application
 Deploying the application Fast and Scaling it according to
your needs
 A Perfect ORM for working with database instead of
database queries
 To develop a secure single page application for either
retrieving data or posting data

Project Structure :
A Django Project when initialised contains basic files by default
such as manage.py, view.py, etc. A simple project structure is
enough to create a single page application.

manage.py-This file is used to interact with your project via


the command line(start the server, sync the database… etc). For
getting the full list of command that can be executed by
manage.py type this code in the command window-

$ python manage.py help

folder ( geeks_site ) – This folder contains all the packages


of your project. Initially it contains four files –

 _init_.py – It is python package.


 settings.py – As the name indicates it contains all the
website settings. In this file we register any applications
we create, the location of our static files, database
configuration details, etc.
 urls.py – In this file we store all links of the project and
functions to call.
 wsgi.py – This file is used in deploying the project in
WSGI. It is used to help your Django application
communicate with the web server.

Creating a basic Project:


 To initiate a project of Django on Your PC, open Terminal
and Enter the following command

django-admin startproject projectName

 A New Folder with name projectName will be created. To


enter in the project using terminal enter command

cd projectName

 Create a new file views.py inside the project folder where


settings.py, urls.py and other files are stored and save the
following code in it-

# HttpResponse is used to pass the information back to


view

from django.http import HttpResponse

# Defining a function which will receive request and


perform task depending upon function definition

def hello_geek (request) :

# This will return Hello Geeks string as


HttpResponse

return HttpResponse("Hello Geeks")

 Open urls.py inside project folder (projectName) and add


your entry-
 Import hello_geek function from views.py file.

from projectName.views import hello_geeks

 Add an entry in url field inside url patterns-

path('geek/', hello_geek),
Now to run the server follow these steps-
 Open command prompt and change directory to env_site
by this command-

$ cd env_site

 Go to Script directory inside env_site and activate virtual


environment-

$ cd Script
$ activate

 Return to the env_site directory and goto the project


directory-

$ cd ..
$ cd geeks_site

 Start the server- Start the server by typing following


command in cmd-

$ python manage.py runserver

You might also like