0% found this document useful (0 votes)
51 views

Django Task

The document provides an introduction and overview of the Django web framework. It discusses what a web framework is, lists some popular frameworks, and describes why Django was chosen. It then covers the key features of Django, including its architecture, which follows the model-view-template (MVT) pattern. Models represent the database, views contain business logic, and templates handle presentation logic. The document also discusses Django projects, apps, templates, views, and models.

Uploaded by

create world
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

Django Task

The document provides an introduction and overview of the Django web framework. It discusses what a web framework is, lists some popular frameworks, and describes why Django was chosen. It then covers the key features of Django, including its architecture, which follows the model-view-template (MVT) pattern. Models represent the database, views contain business logic, and templates handle presentation logic. The document also discusses Django projects, apps, templates, views, and models.

Uploaded by

create world
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

Introduction to Django

BY
T.SRINIVASA REDDY
AGENADA
What is a Web Framework?
List of Software Frameworks
What is a Django?
Features of Django
Django Architecture
What is Web Framework?
Web framework is a set of components designed
to simplify your web development process.
It has basic structuring tools in it, which serve as
a solid base for your project.
 It allows you to focus on the most important
details and project’s goals instead of creating
things, that you can simply pull out of the
framework.”
Benefits of a framework?
Saving software developers time and energy
Makes easier the Development Process
Eases Debugging and Application Maintenance
Improves Database Proficiency
Reduces Code Length
List of Software Frameworks, Tools
Why We Choose Django?
Django is a free and open-source web framework.
It is written in Python.
It follows the Model-View-Template (MVT)
architectural pattern.
It is used by several top websites like Youtube,
Google,Dropbox,Yahoo,Maps,Mozilla,Instagram,
Washington Times,Nasa and many more
Features of Django Framework
Fast: Django was designed to help developers take applications
from concept to completion as quickly as possible
 Fully Loaded:Django includes dozens of extras we can use to
handle common Web development tasks Django takes care of
user authentication, content administration, site maps, RSS
feeds, and many more tasks
 Security:Django takes security seriously and helps developers
avoid many common security mistakes, such as SQL injection,
cross-site scripting, cross-site request forgery and clickjacking.
Its user authentication system provides a secure way to manage
user accounts and passwords.
 Scalability: Some of the busiest sites on the planet use Django’s
ability to quickly and flexibly scale to meet the heaviest traffic
demands
 Vesatile:Companies, organizations and governments have used
Django to build all sorts of things — from content management
systems to social networks to scientific computing platforms.

 NOTE: As Django is specially designed web application


framework, the most commonly required activities will takes
care automatically by Django and Hence Developer's life will be
simplified and we can develop applications very easily.
Django Architecture
 Every website has three main code sections: input logic, business
logic, and user interface logic.

 The Django web framework has a model-view-template (MVT)


architecture, which makes it the only framework you’ll need to
create a complete website or web application. This Python
framework allows you to create models that generate databases
and render dynamic HTML templates to the UI using views.
Django Architecture flow
Django App Structure and Project Structure
Django Project Structure:
 Once we installed django in our system, we will get 'django-admin'
command line tool, which can be used to create our Django project.
 django-admin startproject f irstProject
Django App Structure
 The following is the command to create application.
 python manage.py startapp firstApp
MVT Diagram
M: model Database operations
V: view  Business logic
T: template  presentation Logic
Django Views
 A view is a place where we put our business logic of the
application. The view is a python function which is used to
perform some business logic and return a response to the user.
This response can be the HTML contents of a Web page, or a
redirect, or a 404 error.
 Ex: import datetime  
# Create your views here.  
from django.http import HttpResponse  
def index(request):  
now = datetime.datetime.now()  
 html = "<html><body><h3>Now time is %s.</h3></body></html>" % now  
return HttpResponse(html)    # rendering the template in HttpResponse  
Django Templates
 Django provides a convenient way to generate dynamic HTML pages by
using its template system.
  template consists of static parts of the desired HTML output as well as
some special syntax describing how dynamic content will be inserted.
 Why Django Template?:
 In HTML file, we can't write python code because the code is only
interpreted by python interpreter not the browser. We know that
HTML is a static markup language, while Python is a dynamic
programming language.
 Django template engine is used to separate the design from the python
code and allows us to build dynamic web pages.
Django Template Configuration
 To configure the template system, we have to provide some entries in settings.py file.
TEMPLATES = [  
    {  
        'BACKEND': 'django.template.backends.django. DjangoTemplates',  
        'DIRS': [os.path.join(BASE_DIR,‘ templates')],  
        'APP_DIRS': True,  
        'OPTIONS': {  
             context_ processors': [  
                'django. template. context_processors. debug',  
                'django. template. context_processors.request',  
               'django.contrib.auth.context_processors.auth',  
                'django. contrib. messages.context_processors.messages',  
            ],  
        },  
    },  
]  
Here, we mentioned that our template directory name is templates. By default, DjangoTemplates looks for
a templates subdirectory in each of the INSTALLED_APPS.
Django Model
 In Django, a model is a class which is used to contain essential
fields and methods. Each model class maps to a single table in the
database.
 Django Model is a subclass of django.db.models.Model and each
field of the model class represents a database field (column).

 Django provides us a database-abstraction API which allows us


to create, retrieve, update and delete a record from the mapped
table.

You might also like