KEMBAR78
Advanced Web Technology using Django.pptx
Course Name : Advance Web Technology
Course Code : 21PDS2CC05
Course in-charge
Dr. M. Kriushanth
Assistant Professor
Department of Data Science
St. Joseph’s College (Autonomous)
Tiruchirappalli
Advance Web Technology
Introduction
What is a WEB?
• The Web is the common name for the World Wide Web
Introduction
What is World Wide Web?
• It is an information system where documents and other web
resources are identified by Uniform Resource Locators
(URLs, such as https://example.com/), which may be
interlinked by hypertext, and are accessible over the
Internet.
Introduction
What is Client Server Computing?
• In client server computing,
• The clients requests a resource and the server provides
that resource.
• A server may serve multiple clients at the same time
while a client is in contact with only one server.
• Both the client and server usually communicate via a
computer network but sometimes they may reside
in the same system.
Introduction
Client Server Computing
What is a Web Technology?
• Web technologies are the various tools and techniques that
are utilised in the process of communication between
different types of devices over the internet.
Introduction
Introduction
What is a Web Development?
• Web development refers to the process of creating websites.
The two parts of a typical website
Introduction
Programming Languages And Frameworks
Introduction
Frontend and Backend
Introduction
What is MVC Architecture?
• Model View Controller or MVC as it is popularly
called, is a software design pattern for developing
web applications.
• A Model View Controller pattern is made up of the following
three parts
• Model − The lowest level of the pattern which is responsible for
maintaining data.
• View − This is responsible for displaying all or a portion of the data
to the user.
• Controller − Software Code that controls the interactions between
the Model and View.
MVC Architecture
• Model − The lowest level of the
pattern which is responsible for
maintaining data.
• View − This is responsible for
displaying all or a portion of the
data to the user.
• Controller − Software Code that
controls the interactions between
the Model and View.
Introduction
Unit – I
Introduction
Introduction
What is Django?
• It is a high-level Python web framework that encourages
rapid development and clean, pragmatic design.
• Django makes it easier to build better web apps quickly and
with less code.
• It is written in 100% pure Python code. so you'll need to
install Python on your system.
Why Django Framework?
• 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.
Introduction
MVT Architecture
• Django is based on MVT architecture.
• Model
• View
• Template
• MVT is a software design pattern for developing a
web application.
MVT Architecture
Model:
• Just like the Model in MVC, here as well it has the same
functionality of providing the interface for the data stored
in the database.
View:
• In Django, Views act as a link between the Model data and
the Templates.
MVT Architecture
MVT Architecture
Template
• Just like View in MVC, Django uses templates in its
framework.
• Templates are responsible for the entire User Interface
completely.
• It handles all the static parts of the webpage along with the
HTML, which the users visiting the webpage will perceive.
Control Flow of MVT
• The user sends a URL request for a resource to Django.
• Django framework then searches for the URL resource.
• If the URL path links up to a View, then that particular View
is called.
• The View will then interact with the Model and retrieve the
appropriate data from the database.
• The View then renders back an appropriate template along
with the retrieved data to the user.
Control Flow of MVT
• Rapid Development
• Secure
• Scalable
• Fully loaded
• Versatile
• Open Source
Features of Django
Rapid Development
• Django was designed with the intention to make a framework which
takes less time to build web application.
• The project implementation phase is a very time taken but Django
creates it rapidly.
Secure
• Django takes security seriously and helps developers to avoid many
common security mistakes, such as SQL injection, cross-site
scripting, cross-site request forgery etc.
• Its user authentication system provides a secure way to manage user
accounts and passwords.
Features of Django
Features of Django
Scalable
• Django is scalable in nature and has ability to quickly and flexibly switch
from small to large scale application project.
Fully loaded
• Django includes various helping task modules and libraries which can
be used to handle common Web development tasks.
• Django takes care of user authentication, content administration, site
maps, RSS feeds etc.
Features of Django
Versatile
• Django is versatile in nature which allows it to build applications for
different-different domains.
• Now a days, Companies are using Django to build various types of
applications like: content management systems, social networks
sites or scientific computing platforms etc.
Open Source
• Django is an open source web application framework.
• It is publicly available without cost.
• It can be downloaded with source code from the public repository. Open
source reduces the total cost of the application development.
What is pip?
• Python Package Index(pip)
• It is a package manager for Python and is included
by default with the Python installer
• It helps to install and uninstall Python packages
Install Django
Install Django
Setting up a virtual environment
• VirtualEnv helps you create a Local Environment(not
System wide) Specific to the Project you are working
upon.
• If you are start working on Multiple projects, your projects
would have different Dependencies (e.g different
Django versions) hence you would need a different virtual
Environment for each Project. VirtualEnv does this for you.
Install Django
Django Environment
Step 1: Install Python
Step 2: Install Virtual Environment
Step 3: Install Django
Step 4: Database Setup
Step 5 : Web Server
Install Django
• python --version
• pip --version
• pip install virtualenv
• pip install Django
Django Project
Command to Create a Project
django-admin startproject projectname
Django Project Structure
hello_world/
manage.py
hello_world/
__init__.py
settings.py
asgi.py
urls.py
wsgi.py
Django Project Structure
manage.py
• This file is used basically as a command-line utility and for
deploying, debugging, or running our web application.
• This file contains code for runserver, or makemigrations or
migrations, etc. that we use in the shell.
runserver : This command is used to run the server for our web application.
Migration : This is used for applying the changes done to our models into the database.
if we make any changes to our database then we use migrate command.
This is used the first time we create a database.
Makemigratio
n
: This is done to apply new migrations that have been carried out due to the
changes in the database.
_init_.py
• This file remains empty and is present their only to tell that
this particular directory(in this case django_project) is a
package.
Settings.py
• This file is present for adding all the applications and the
middleware application present.
• Also, it has information about templates and databases.
• Overall, this is the main file of our Django web
application.
Django Project Structure
urls.py
• This file handles all the URLs of our web application.
• This file has the lists of all the endpoints that will have for our
website.
What is Web Endpoint?
• A web service endpoint is a web address or URL where your
service can be accessed by a client application.
Django Project Structure
wsgi.py(Synchronous server)
• WSGI, short for Web Server Gateway Interface.
• It is a specification that describes how a web server
communicates with web applications, and how web
applications can be chained together to process one request.
• It is used for deploying our applications on to servers like
Apache etc.
Django Project Structure
Limitations wsgi.py(Synchronous server)
• WSGI compatible servers are synchronous
• This means it blocks each request until a response arrives from
the application.
• Blocking requests prevent additional requests from being
processed
• WSGI implementations (which are multi-threaded) create a thread for
each request
Django Project Structure
Limitations wsgi.py(Synchronous server)
Django Project Structure
asgi.py
• ASGI, or the Asynchronous Server Gateway Interface
• It is structured as a single, asynchronous callable
• It is available in the newer versions of Django.
• ASGI can be considered as a succeeder interface to the WSGI.
• It work similar to WSGI
• It gives better freedom in Django development.
• This not only allows multiple incoming events and outgoing events for each
application, but also allows for a background coroutine. so the application can
do other things (such as listening for events on an external trigger).
Django Project Structure
Django Project
Starting a Server
python manage.py runserver
Stopping a Server
Press +
Press Ctrl + Break Button
Django Project
Migration
Python manage.py migrate
Starting an Application
python manage.py startapp Application name
Django Project
View.py
from django.http import HttpResponse
def sayDemo(request):
return HttpResponse("My First Django Program")
Django Project
Setting.py
Under Installed Apps function
Mention the appname
Django Project
urls.py
path(‘name/', view function name),
path(‘Display/', sayDemo),
Django Project
Creating user
Stop the Server
python manage.py createsuperuser
User name:
Email:
Password:
Password(again):
Introduction
1. Create the Project
2. Migrate it
3. Create app
4. Copy the URL
View Function
• 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.
• All the view function are created inside the views.py file of
the Django app.
Creating Simple View
Simple View
create a simple view in myapp to say "welcome to my
app!“
from django.http import HttpResponse
def hello(request):
return HttpResponse("<h1>welcome to my app !</h1>")
Django- Template
• Django provides a convenient way to generate
dynamic HTML pages by using its template system.
• Django makes it possible to separate python and
HTML
• The python goes in views
• HTML goes in templates.
• To link the two, Django relies on the render function and
the Django Template Language(DTL).
Django Template Language (DTL)
• Django template uses its own syntax to deal with
variable, tags, expressions etc.
• A template is rendered with a context which is used to
get value at a web page.
Django Template Language (DTL)
Variable
• Variables associated with a context can be accessed by
{{}} (double curly braces)
My name is {{name}}.
My name is rahul
Django Template Language (DTL)
Tags
• In a template, Tags provide arbitrary logic in the
rendering process.
• A tag can output content, serve as a control structure
• Tags are surrounded by {% %} braces
The Render Function
This function takes three parameters
• Request
• The path to the template
• Dictionary of parameters
def hello(request):
return render(request,’home.html’,{‘name’:’sam’})
The Render Function
• Request
• The initial request.
• The path to the template
• This is the path relative to the TEMPLATE_DIRS option in the project
settings.py variables.
• Dictionary of parameters
• A dictionary that contains all variables needed in the template. This
variable can be created or you can use locals() to pass all local variable
declared in the view.
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',
],
},
},
]
Django Template Creation
Step 1: create a directory templates inside the project app
Step 2: After that create a template index.html inside the created folder.
Step 3: Create HTML coding's in the index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Index</title>
</head>
<body>
<h2>Welcome to Django!!!</h2>
</body>
</html>
Django URL Mapping
• Django is a web application framework.
• It gets user requests by URL locater and responds back.
• To handle URL, django.urls module is used by the
framework.
• urls.py
from django.contrib import admin
from django.urls import path
urlpatterns = [
path('admin/', admin.site.urls),
]
References
1. https://www.tutorialspoint.com/django/django_basics.htm Date : 21-12-
2020
2. https://www.javatpoint.com/django-tutorial Date : 21-12-2020
3. https://www.fullstackpython.com/django.html Date : 22-12-2020
4. https://simpleisbetterthancomplex.com/series/2017/09/04/a-complete-begi
nners-guide-to-django-part-1.html
Date : 26-12-2020
THANK YOU

Advanced Web Technology using Django.pptx

  • 1.
    Course Name :Advance Web Technology Course Code : 21PDS2CC05 Course in-charge Dr. M. Kriushanth Assistant Professor Department of Data Science St. Joseph’s College (Autonomous) Tiruchirappalli
  • 2.
  • 3.
    Introduction What is aWEB? • The Web is the common name for the World Wide Web
  • 4.
    Introduction What is WorldWide Web? • It is an information system where documents and other web resources are identified by Uniform Resource Locators (URLs, such as https://example.com/), which may be interlinked by hypertext, and are accessible over the Internet.
  • 5.
    Introduction What is ClientServer Computing? • In client server computing, • The clients requests a resource and the server provides that resource. • A server may serve multiple clients at the same time while a client is in contact with only one server. • Both the client and server usually communicate via a computer network but sometimes they may reside in the same system.
  • 6.
  • 7.
    What is aWeb Technology? • Web technologies are the various tools and techniques that are utilised in the process of communication between different types of devices over the internet. Introduction
  • 8.
    Introduction What is aWeb Development? • Web development refers to the process of creating websites. The two parts of a typical website
  • 9.
  • 10.
  • 11.
    Introduction What is MVCArchitecture? • Model View Controller or MVC as it is popularly called, is a software design pattern for developing web applications. • A Model View Controller pattern is made up of the following three parts • Model − The lowest level of the pattern which is responsible for maintaining data. • View − This is responsible for displaying all or a portion of the data to the user. • Controller − Software Code that controls the interactions between the Model and View.
  • 12.
    MVC Architecture • Model− The lowest level of the pattern which is responsible for maintaining data. • View − This is responsible for displaying all or a portion of the data to the user. • Controller − Software Code that controls the interactions between the Model and View. Introduction
  • 13.
  • 14.
    Introduction What is Django? •It is a high-level Python web framework that encourages rapid development and clean, pragmatic design. • Django makes it easier to build better web apps quickly and with less code. • It is written in 100% pure Python code. so you'll need to install Python on your system.
  • 15.
    Why Django Framework? •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. Introduction
  • 16.
    MVT Architecture • Djangois based on MVT architecture. • Model • View • Template • MVT is a software design pattern for developing a web application.
  • 17.
  • 18.
    Model: • Just likethe Model in MVC, here as well it has the same functionality of providing the interface for the data stored in the database. View: • In Django, Views act as a link between the Model data and the Templates. MVT Architecture
  • 19.
    MVT Architecture Template • Justlike View in MVC, Django uses templates in its framework. • Templates are responsible for the entire User Interface completely. • It handles all the static parts of the webpage along with the HTML, which the users visiting the webpage will perceive.
  • 20.
    Control Flow ofMVT • The user sends a URL request for a resource to Django. • Django framework then searches for the URL resource. • If the URL path links up to a View, then that particular View is called. • The View will then interact with the Model and retrieve the appropriate data from the database. • The View then renders back an appropriate template along with the retrieved data to the user.
  • 21.
  • 22.
    • Rapid Development •Secure • Scalable • Fully loaded • Versatile • Open Source Features of Django
  • 23.
    Rapid Development • Djangowas designed with the intention to make a framework which takes less time to build web application. • The project implementation phase is a very time taken but Django creates it rapidly. Secure • Django takes security seriously and helps developers to avoid many common security mistakes, such as SQL injection, cross-site scripting, cross-site request forgery etc. • Its user authentication system provides a secure way to manage user accounts and passwords. Features of Django
  • 24.
    Features of Django Scalable •Django is scalable in nature and has ability to quickly and flexibly switch from small to large scale application project. Fully loaded • Django includes various helping task modules and libraries which can be used to handle common Web development tasks. • Django takes care of user authentication, content administration, site maps, RSS feeds etc.
  • 25.
    Features of Django Versatile •Django is versatile in nature which allows it to build applications for different-different domains. • Now a days, Companies are using Django to build various types of applications like: content management systems, social networks sites or scientific computing platforms etc. Open Source • Django is an open source web application framework. • It is publicly available without cost. • It can be downloaded with source code from the public repository. Open source reduces the total cost of the application development.
  • 26.
    What is pip? •Python Package Index(pip) • It is a package manager for Python and is included by default with the Python installer • It helps to install and uninstall Python packages Install Django
  • 27.
    Install Django Setting upa virtual environment • VirtualEnv helps you create a Local Environment(not System wide) Specific to the Project you are working upon. • If you are start working on Multiple projects, your projects would have different Dependencies (e.g different Django versions) hence you would need a different virtual Environment for each Project. VirtualEnv does this for you.
  • 28.
  • 29.
    Django Environment Step 1:Install Python Step 2: Install Virtual Environment Step 3: Install Django Step 4: Database Setup Step 5 : Web Server
  • 30.
    Install Django • python--version • pip --version • pip install virtualenv • pip install Django
  • 31.
    Django Project Command toCreate a Project django-admin startproject projectname
  • 32.
  • 33.
    Django Project Structure manage.py •This file is used basically as a command-line utility and for deploying, debugging, or running our web application. • This file contains code for runserver, or makemigrations or migrations, etc. that we use in the shell. runserver : This command is used to run the server for our web application. Migration : This is used for applying the changes done to our models into the database. if we make any changes to our database then we use migrate command. This is used the first time we create a database. Makemigratio n : This is done to apply new migrations that have been carried out due to the changes in the database.
  • 34.
    _init_.py • This fileremains empty and is present their only to tell that this particular directory(in this case django_project) is a package. Settings.py • This file is present for adding all the applications and the middleware application present. • Also, it has information about templates and databases. • Overall, this is the main file of our Django web application. Django Project Structure
  • 35.
    urls.py • This filehandles all the URLs of our web application. • This file has the lists of all the endpoints that will have for our website. What is Web Endpoint? • A web service endpoint is a web address or URL where your service can be accessed by a client application. Django Project Structure
  • 36.
    wsgi.py(Synchronous server) • WSGI,short for Web Server Gateway Interface. • It is a specification that describes how a web server communicates with web applications, and how web applications can be chained together to process one request. • It is used for deploying our applications on to servers like Apache etc. Django Project Structure
  • 37.
    Limitations wsgi.py(Synchronous server) •WSGI compatible servers are synchronous • This means it blocks each request until a response arrives from the application. • Blocking requests prevent additional requests from being processed • WSGI implementations (which are multi-threaded) create a thread for each request Django Project Structure
  • 38.
  • 39.
    asgi.py • ASGI, orthe Asynchronous Server Gateway Interface • It is structured as a single, asynchronous callable • It is available in the newer versions of Django. • ASGI can be considered as a succeeder interface to the WSGI. • It work similar to WSGI • It gives better freedom in Django development. • This not only allows multiple incoming events and outgoing events for each application, but also allows for a background coroutine. so the application can do other things (such as listening for events on an external trigger). Django Project Structure
  • 40.
    Django Project Starting aServer python manage.py runserver Stopping a Server Press + Press Ctrl + Break Button
  • 41.
    Django Project Migration Python manage.pymigrate Starting an Application python manage.py startapp Application name
  • 42.
    Django Project View.py from django.httpimport HttpResponse def sayDemo(request): return HttpResponse("My First Django Program")
  • 43.
    Django Project Setting.py Under InstalledApps function Mention the appname
  • 44.
    Django Project urls.py path(‘name/', viewfunction name), path(‘Display/', sayDemo),
  • 45.
    Django Project Creating user Stopthe Server python manage.py createsuperuser User name: Email: Password: Password(again):
  • 46.
    Introduction 1. Create theProject 2. Migrate it 3. Create app 4. Copy the URL
  • 47.
    View Function • Aview 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. • All the view function are created inside the views.py file of the Django app.
  • 48.
    Creating Simple View SimpleView create a simple view in myapp to say "welcome to my app!“ from django.http import HttpResponse def hello(request): return HttpResponse("<h1>welcome to my app !</h1>")
  • 49.
    Django- Template • Djangoprovides a convenient way to generate dynamic HTML pages by using its template system. • Django makes it possible to separate python and HTML • The python goes in views • HTML goes in templates. • To link the two, Django relies on the render function and the Django Template Language(DTL).
  • 50.
    Django Template Language(DTL) • Django template uses its own syntax to deal with variable, tags, expressions etc. • A template is rendered with a context which is used to get value at a web page.
  • 51.
    Django Template Language(DTL) Variable • Variables associated with a context can be accessed by {{}} (double curly braces) My name is {{name}}. My name is rahul
  • 52.
    Django Template Language(DTL) Tags • In a template, Tags provide arbitrary logic in the rendering process. • A tag can output content, serve as a control structure • Tags are surrounded by {% %} braces
  • 53.
    The Render Function Thisfunction takes three parameters • Request • The path to the template • Dictionary of parameters def hello(request): return render(request,’home.html’,{‘name’:’sam’})
  • 54.
    The Render Function •Request • The initial request. • The path to the template • This is the path relative to the TEMPLATE_DIRS option in the project settings.py variables. • Dictionary of parameters • A dictionary that contains all variables needed in the template. This variable can be created or you can use locals() to pass all local variable declared in the view.
  • 55.
    Django Template Configuration Toconfigure 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', ], }, }, ]
  • 56.
    Django Template Creation Step1: create a directory templates inside the project app Step 2: After that create a template index.html inside the created folder. Step 3: Create HTML coding's in the index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Index</title> </head> <body> <h2>Welcome to Django!!!</h2> </body> </html>
  • 57.
    Django URL Mapping •Django is a web application framework. • It gets user requests by URL locater and responds back. • To handle URL, django.urls module is used by the framework. • urls.py from django.contrib import admin from django.urls import path urlpatterns = [ path('admin/', admin.site.urls), ]
  • 58.
    References 1. https://www.tutorialspoint.com/django/django_basics.htm Date: 21-12- 2020 2. https://www.javatpoint.com/django-tutorial Date : 21-12-2020 3. https://www.fullstackpython.com/django.html Date : 22-12-2020 4. https://simpleisbetterthancomplex.com/series/2017/09/04/a-complete-begi nners-guide-to-django-part-1.html Date : 26-12-2020
  • 59.