SCHOOL OF INFORMATION TECHNOLOGY
&ENGINEERING
October, 2022
A project report on
Web Based Application (Off-Campus Internship)
Submitted in partial fulfilment for the award of the degree of
MCA
By
Manaswi Gautam (21MCA0039)
Under the guidance
of
Dr. Neelu Khare
Professor Grade 1
OBJECTIVES
The Company works on mainly web based applications under which they have
different department. In my Internship, I am getting training for the Django, so
I can work as a Backend Developer. The project is related to a shopping Web
Application in which consists of two parts, first is used by the customer that is
called front-end and the second is admin part where all the activities will be
monitored, for both the parts the backend design is assigned to me. The basic
output of the project will be a web based application for online shopping
purpose.
Software Used:
1. ATOM
2. PYCHARM
3. GITBASH TERMINAL
4. WEB BROWSER(As a Server)
Hardware Requirements:
1. RAM (1GB MINIMUM)
2. INTERNET CONNECTION
3. MEMORY(256GB MINIMUM)
4. PROCESSOR(I3)
5. PROCESSOR CORES (DUAL CORE).
TECHNOLOGY USED TO ACHIEVE THE IDENTIFIED OBJECTIVES
For implementing frontend part of the project we are using HTML, CSS,
Bootstrap, and React JS and for backend part we are using Django, Python and
in future we may use more technologies. Presently I am designing backend
using Django and later I will use React JS for linking it with code.
Django is a high-level Python web framework that encourages rapid
development with clean and pragmatic design. It is built by experienced
developers, it takes care of most of the hassles occurring in web development,
it focuses on writing the app without requiring to reinvent the wheel. It’s free
and open source.
About Django:
Complete
Django follows the "Batteries included" philosophy and provides almost
everything to the developers that they want to do "out of the box". Because
everything needed by a developer is a part of the "product". It all works
together, follows consistency, design principles, and provides extensive up-to-
date documentation.
Versatile
Django can be (and has been) used to build almost any type of website — from
content management systems and wikis, through to social networks and news
sites. It can work with any client-side framework, and can deliver content in
almost any format (including HTML, RSS feeds, JSON, and XML). Internally,
while it provides choices for almost any functionality you might want (e.g.
several popular databases, templating engines, etc.), it can also be extended to
use other components if needed.
Secure
Django helps developers to avoid many common security mistakes by
providing a framework that has been engineered to "do the right things" to
protect the website automatically. For example, Django provides a secure way
to manage user accounts and passwords, avoiding common mistakes like
putting session information in cookies where it is vulnerable (instead cookies
just contain a key, and the actual data is stored in the database) or directly
storing passwords rather than a password hash.
A password hash is a fixed-length value created by sending the password
through a cryptographic hash function. Django can check if an entered
password is correct by running it through the hash function and comparing the
output to the stored hash value. However due to the "one-way" nature of the
function, even if a stored hash value is compromised it is hard for an attacker
to work out the original password.
Django enables protection against many vulnerabilities by default, including
SQL injection, cross-site scripting, cross-site request forgery and click jacking
Scalable
Django uses a component-based "shared-nothing" architecture (each part of
the architecture is independent of the others, and can hence be replaced or
changed if needed). Having a clear separation between the different parts
means that it can scale for increased traffic by adding hardware at any level:
caching servers, database servers, or application servers. Some of the busiest
sites have successfully scaled Django to meet their demands (e.g. Instagram
and Disqus).
Maintainable
Django code is written using design principles and patterns that encourage the
creation of maintainable and reusable code. In particular, it makes use of the
Don't Repeat Yourself (DRY) principle so there is no unnecessary duplication,
reducing the amount of code. Django also promotes the grouping of related
functionality into reusable "applications" and, at a lower level, groups related
code into modules (along the lines of the Model View Controller (MVC)
pattern).
Portable
Django is written in Python, which runs on many platforms. That means that
you are not tied to any particular server platform, and can run your
applications on many flavors of Linux, Windows, and macOS. Furthermore,
Django is well-supported by many web hosting providers, who often provide
specific infrastructure and documentation for hosting Django sites.
What does Django code look like?
In a traditional data-driven website, a web application waits for HTTP requests
from the web browser (or other client). When a request is received the
application works out what is needed based on the URL and possibly
information in POST data or GET data. Depending on what is required it may
then read or write information from a database or perform other tasks
required to satisfy the request. The application will then return a response to
the web browser, often dynamically creating an HTML page for the browser to
display by inserting the retrieved data into placeholders in an HTML template.
Django web applications typically group the code that handles each of these
steps into separate files:
URLs: While it is possible to process requests from every single URL via a
single function, it is much more maintainable to write a separate view
function to handle each resource. A URL mapper is used to redirect HTTP
requests to the appropriate view based on the request URL. The URL
mapper can also match particular patterns of strings or digits that
appear in a URL and pass these to a view function as data.
View: A view is a request handler function, which receives HTTP
requests and returns HTTP responses. Views access the data needed to
satisfy requests via models, and delegate the formatting of the response
to templates.
Models: Models are Python objects that define the structure of an
application's data, and provide mechanisms to manage (add, modify,
delete) and query records in the database.
Templates: A template is a text file defining the structure or layout of a
file (such as an HTML page), with placeholders used to represent actual
content. A view can dynamically create an HTML page using an HTML
template, populating it with data from a model. A template can be used
to define the structure of any type of file; it doesn't have to be HTML!
Sending request to the right view (urls.py)
A URL mapper is typically stored in a file named urls.py. In the example below,
the mapper (URL patterns) defines a list of mappings between routes (specific
URL patterns) and corresponding view functions. If an HTTP Request is received
that has a URL matching a specified pattern, then the associated view function
will be called and passed the request.
urlpatterns = [
path('admin/', admin.site.urls),
path('book/<int:id>/', views.book_detail, name='book_detail'),
path('catalog/', include('catalog.urls')),
re_path(r'^([0-9]+)/$', views.best),
]
The urlpatterns object is a list of path () and/or re_path () functions (Python
lists are defined using square brackets, where items are separated by commas
and may have an optional trailing comma. For example: [item1, item2,
item3,]).
The first argument to both methods is a route (pattern) that will be matched.
The path() method uses angle brackets to define parts of a URL that will be
captured and passed through to the view function as named arguments.
The re_path () function uses a flexible pattern matching approach known as a
regular expression.
The second argument is another function that will be called when the pattern
is matched. The notation views.book detail indicates that the function is
called bookdetail () and can be found in a module called views (i.e. inside a file
named views.py)
Handling the request (views.py)
Views are the heart of the web application, receiving HTTP requests from web
clients and returning HTTP responses. In between, they marshal the other
resources of the framework to access databases, render templates, etc.
The example below shows a minimal view function index (), which could have
been called by our URL mapper in the previous section. Like all view functions
it receives an Http Request object as a parameter (request) and returns an Http
Response object. In this case we don't do anything with the request, and our
response returns a hard-coded string. We'll show you a request that does
something more interesting in a later section.
# filename: views.py (Django view functions)
from django.http import HttpResponse
def index(request):
# Get an HttpRequest - the request parameter
# perform operations using information from the request.
# Return HttpResponse
return HttpResponse('Hello from Django!')
Defining data models (models.py)
Django web applications manage and query data through Python objects
referred to as models. Models define the structure of stored data, including
the field types and possibly also their maximum size, default values, selection
list options, help text for documentation, label text for forms, etc. The
definition of the model is independent of the underlying database — you can
choose one of several as part of your project settings. Once you've chosen
what database you want to use, you don't need to talk to it directly at all —
you just write your model structure and other code, and Django handles all the
"work" of communicating with the database.
*COMPARING RELATED TECHNOLOGIES THAT CAN BE USED TO
REALIZE THE IDENTIFIED OBJECTIVES –
The technologies which can be used in place of Django are-
1. Turbogears:
Based on the MVC (Model-View-Controller) design pattern, TurboGears is a
full-stack framework for developing web applications. It is flexible, portable,
and comes with a fully integrated MochiKit JavaScript library.
TurboGears applications can be deployed on any web server that supports the
WSGI Python interface. In addition, it comes attached with Gearbox, a
command-line interface for managing projects, and Kajiki, a templating engine.
It is perfect for handling database-driven websites as it has an open-source SQL
kit known as SQLAlchemy. It also has support for SQLObject, which is a
powerful Object-relational mapping package that lets you write server-side
code very quickly, in just a few days.
TurboGears can be considered the best alternative to Django, if you are looking
for a framework that is most similar to Django. Both have powerful template
engine, high-powered ORM, database support, and are extensible, but
TurboGears is not as opinionated.
2. Web2py:
Web2py is a web-based framework that allows you to create, modify, deploy
and manage apps from anywhere using your browser. It is a cross-platform
framework that can be used on multiple devices and browsers. It also deploys
a powerful error logging and ticketing system.
Web2py has no dependencies outside of the Python standard library. It
requires no prerequisites for installation or configuration. Along with backward
compatibility, it also has security measures against attacks such as cross-site
scripting, SQL injection and other malicious attacks.
It has a fully-featured IDE, which allows you to change the content on your
website from any web browser, even after it is deployed. You can develop fast,
scalable, secure database-driven web applications with Web2py.
3. CubicWeb
CubicWeb is a free, open-source semantic web application framework that
works on a data model. Developers can develop web applications efficiently by
reusing components called cubes. It employs object-oriented design principles
and has an embedded query language.
CubicWeb also includes Relational Query Language (RQL) which simplifies data-
related queries using a simple syntax. You are able to manage relationship
queries, data repositories, and view attributes.
CubicWeb offers semi-automatic mechanisms for handling XML and JSON code
generation, and workflow with security. Large-scale semantic websites and
linked open data apps are good for using CubicWeb.
4. Microframework:
Django, can sometimes be monolithic. Other full stack frameworks can also be
too complex for small, basic websites and applications that do not require a lot
of features. Python has a series of well-designed micro frameworks such as
Flask, Bottle and CherryPy that work perfectly with small-scale websites.
Some advantages of using micro-frameworks are –
Simple, easy to use, lightweight, and small footprint
URL routing through REST API
A good choice for small web projects such as static websites or one page
applications
Uses WSGI to work with HTTP request
5. CherryPy:
CherryPy is a python based, object-oriented web development framework. It
provides built-in capital plugins and a powerful configuration system.
CherryPy also includes an implementation of the Ruby programming language
framework. It incorporates the Ruby on Rail’s routing system in Python. You
can generate and map URLs to controllers.
CherryPy requires minimal lines to write the source code resulting in low
development time and high productivity.
It is a very lightweight alternative for Django and one of the oldest Python
frameworks. CherryPy has built-in tools for coding static web pages, URL
encoding, user authentication, and session management. It is also embedded
with a powerful configuration system that can handle multiple HTTP requests
and run multiple HTTP servers simultaneously.
6. Pyramid:
Pyramid is the most flexible Python framework available .A lightweight,
scalable framework, Pyramid is used for developing small to large-scale web
apps. It is also great for quick prototyping and for developers who are working
on API projects.
Pyramid has a small footprint but it is easily extendable with add-ons,
configurations and libraries to include unique functionalities in your app. It
sometimes provides so many options that it can get tough to make the right
choices in a new project.
Major companies such as Dropbox, Fedora, Mozilla, SurveyMonkey, and
Yelp use Pyramid for website development.
7. Bottle
The bottle is a simple, fast, and lightweight web-based framework distributed
as a single file module. It works on any Python WSGI compliant server and is
mainly used for building APIs. It is also a preferred choice for building simple
prototypes.
It has support for various databases and URL parameters along with the built-
in template engine Simple Template. It is also highly flexible and allows you to
integrate third-party templating engines such as Mako, Jinja2, or Cheetah.
There are plugins and external libraries available for ORM support, NoSQL
database, and admin panels.
8. Falcon
Falcon is a reliable, high-performance Python WSGI library for rapid backend
development. It is mainly used for micro web services, Web API, web sockets,
and back-ends of large-scale applications. It encourages usage of REST
architectural style, very much like the Django Rest framework, and tries to do
as little as possible.
It is highly effective and cuts down internal dependencies by using a clean
HTTP and REST framework architecture design. High performance with a
significantly lower code base, Falcon is a minimalistic alternative to Django.