WEB DEVELOPMENT USING DJANGO
-G.JYOTHSNA
(318126512137)
INTRODUCTION
• Django is a web application framework written in Python programming language. It
is an open-source python web framework used for rapid development, pragmatic,
maintainable, clean design, and secures websites.
• Django primary goal is to ease the development of complex and data-based
powered websites. A web application framework is a toolkit of all components
needed for application development.
• The main goal of the Django framework is to allow developers to focus on
components of the application that are new instead of spending time on already
developed components.
• Django is designed in such a manner that it handles much of configuring things
automatically.
• Another point of importance is that Django includes all the functionalities to secure
websites and helps developers avoid web security mistakes.
HISTORY OF DJANGO
• 2003- started by Adrian Holovaty and Simon Willison as
internal project at the Lawrence journal world newspaper.
• 2005- publicly released under BSD license in 21, July 2005 and
named it Django.
• Currently, DSF (Django Software Foundation) maintains its
development and release cycle.
• Django is now an open source project with contributors across
the world.
ADVANTAGES OF DJANGO
• Object-Relational Mapping (ORM) Support
• Administration GUI
• Development Environment
• Less Coding
• Don't Repeat Yourself (DRY)
• Fast Development
FEATURES OF DJANGO
• Rapid Development
• Secure
• Scalable
• Open Source
• Vast and Supported Community
DJANGO MVC-MVT PATTERN
PROJECT CREATION, APP CREATION
Creating the project:
• Open a command shell (or a terminal window), and make sure you are in
your virtual environment.
• Navigate to where you want to store your Django apps (make it
somewhere easy to find like inside your Documents folder), and create a
folder for your new website (in this case: django_projects). Then change
into your newly-created directory:
mkdir django_projects
cd django_projects
• Create the new project using the django-admin startproject command as
shown, and then change into the project folder:
django-admin startproject locallibrary
cd locallibrary
HTTP REQUEST AND RESPONSES:
Django uses request and response objects to pass state through the system.
When a page is requested, Django creates an HttpRequest object that contains metadata about
the request. Then Django loads the appropriate view, passing the HttpRequest as the first
argument to the view function. Each view is responsible for returning an HttpResponse object.
Example Code:
views.py
# importing HttResponse from library
from django.http import HttpResponse
def home(request):
# request is handled using HttpResponse object
return HttpResponse("Any kind of HTML Here")
urls.py
# importing view from views.py
from .views import home
urlpatterns = [
path('', home),
]
HTML FORMS
• In HTML, a form is a collection of elements inside <form>...</form> that allow
a visitor to do things like enter text, select options, manipulate objects or
controls, and so on, and then send that information back to the server.
• Some of these form interface elements - text input or checkboxes - are built
into HTML itself. Others are much more complex; an interface that pops up a
date picker or allows you to move a slider or manipulate controls will typically
use JavaScript and CSS as well as HTML form <input> elements to achieve
these effects.
• Django handles three distinct parts of the work involved in forms:
preparing and restructuring data to make it ready for rendering
creating HTML forms for the data.
receiving and processing submitted forms and data from the client
In the context of a Web application, ‘form’ might refer to that HTML <form>,
or to the Django Form that produces it, or to the structured data returned
when it is submitted, or to the end-to-end working collection of these parts.
SUPERUSER CREATION:
• Django provides us Admin Panel for it’s users. So we need not worry about
creating a separate Admin page or providing authentication feature as Django
provides us that feature.
• For creating superuser, first reach the same directory as that
of manage.py and run the following command:
python manage.py createsuperuser
Then enter the Username of your choice and press enter.
THE DJANGO TEMPLATE LANGUAGE
• Variables
• Tags
• Filters
• Components
1. Engine
2. Template
3. Context
4. Loaders
5. Context Processors
CRUD OPERATIONS
• CRUD stands for Create, Read, Update & Delete
Django CRUD Function Based Views:
• Create View
• Retrieve View
• List View
• Detail View
• Update View
• Delete View
Thank YOU