1 Python: Approval II Abstract III
1 Python: Approval II Abstract III
Approval ii
Abstract iii
1 Python
1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.2 History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.3 Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.4 Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2. Django
2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2 History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.3 Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.3.1 Complete
2.3.2 Versatile
2.3.3 Secure
2.3.4 Scalable
2.3.5 Maintainable
2.3.6 Portable
3. Django Architecture and Code
3.1 Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4. My Project
4.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.2 Goals
5. Website Overview
5.10 GET PG
1.2 History
When we talk about the history of Python, we cannot miss ABC programming language because
it was ABCs influence that led to the design and development of programming language called
Python.
In the early 1980s, Van Rossum used to work at CWI (Centrum voor Wiskunde en Informatica) as
an implementer of the programming language called ABC. Later at CWI in the late 1980s, while
working on a new distributed operating system called AMOEBA, Van Rossum started looking for
a scripting language with a syntax like ABC but with the access to the Amoeba system calls. So
Van Rossum himself started designing a new simple scripting language that could overcome the
flaws of ABC.
1
Van Rossum started developing the new script in the late 1980s and finally introduced the first
version of that programming language in 1991. This initial release has module system of Modula-
3. Later on, this programming language was named ‘Python’.
Guido Van Rossum published the first version of Python code (version 0.9.0) at alt.sources in
February 1991. This release included already exception handling, functions, and the core data types
of list, dict, str and others. It was also object oriented and had a module system.
Python version 1.0 was released in January 1994. The major new features included in this release
were the functional programming tools lambda, map, filter and reduce, which Guido Van Rossum
never liked.
Six and a half years later in October 2000, Python 2.0 was introduced. This release included list
comprehensions, a full garbage collector and it was supporting unicode.
Python flourished for another 8 years in the versions 2.x before the next major release as Python
3.0 (also known as "Python 3000" and "Py3K") was released. Python 3 is not backwards
compatible with Python 2.x. The emphasis in Python 3 had been on the removal of duplicate
programming constructs and modules, thus fulfilling or coming close to fulfilling the 13th law of
the Zen of Python: "There should be one -- and preferably only one -- obvious way to do it."
1.3 Features
Python has some irresistible key features which need to be understood before getting your hands
dirty with python coding:
2
Great thing about Python is that it has support for both procedure-oriented
programming as well as object-oriented programming. The programs for procedure-
oriented languages are built around functions or procedures and can be reused. In
object-oriented languages, the program is built around objects which combine data and
functionality. An object-oriented language includes data and functionality in their
object. Unlikely many big languages like C++ or Java, Python comes with a very
powerful and simple way of using object-oriented programming.
1.4 Libraries
Python's large standard library, commonly cited as one of its greatest strengths, provides tools
suited to many tasks. For Internet-facing applications, many standard formats and protocols such
as MIME and HTTP are supported. It includes modules for creating graphical user interfaces,
connecting to relational databases, generating pseudorandom numbers, arithmetic with arbitrary-
precision decimals, manipulating regular expressions, and unit testing.
Some parts of the standard library are covered by specifications (for example, the Web Server
Gateway Interface (WSGI) implementation wsgiref follows PEP 333), but most modules are not.
3
They are specified by their code, internal documentation, and test suites (if supplied). However,
because most of the standard library is cross-platform Python code, only a few modules need
altering or rewriting for variant implementations.
As of March 2018, the Python Package Index (PyPI), the official repository for third-party Python
software, contains over 130,000 packages with a wide range of functionality, including: Graphical
user interface
Web frameworks
Multimedia
Databases
Networking
Test frameworks
Automation
Web scraping
Image Processing
System administration
Scientific computing
Text processing
Generally, there are two types of Python framework used while developing applications.
5
1.5.2 Non-Full-Stack Frameworks
6
2. Django
2.1 Introduction
Django is a Python-based web framework which allows you to quickly create web application without
all of the installation or dependency problems that you normally will find with other frameworks.
When you’re building a website, you always need a similar set of components: a way to handle user
authentication (signing up, signing in, signing out), a management panel for your website, forms, a
way to upload files, etc. Django gives you ready-made components to use.
Django is used in many popular sites like as: Disqus, Instagram, Knight Foundation, MacArthur
Foundation, Mozilla, National Geographic etc. There are more than 5k online sites based on the Django
framework.
Sites like Hot Frameworks assess the popularity of a framework by counting the number of GitHub
projects and StackOverflow questions for each platform, here Django is in 6th position. Web
frameworks often refer to themselves as “opinionated” or “un-opinionated” based on opinions about
the right way to handle any particular task. Django is somewhat opinionated, hence delivers the in both
worlds( opinionated & un-opinionated ).
2.2 History
Django was design and developed by Lawrence journal world in 2003 and publicly released under
BSD license in July 2005. Currently, DSF (Django Software Foundation) maintains its development
and release cycle. Django was released on 21, July 2005. Its current stable version is 2.0.3 which was
released on 6 March, 2018.
Here’s an overview of when deprecated features will be dropped in Django going forward:
7
1.10 - Aug. 2016: Drop deprecation shims added in 1.8. This still allows running code that was
deprecation-warning free on 1.8; the shims dropped are for supporting older unsupported
versions.
1.11 - April 2017 (LTS): No deprecation shims dropped. The 1.9 deprecation shims are needed
to help apps maintain compatibility back to 1.8 LTS.
2.0 - Dec. 2017: Drop deprecation shims added in 1.9 and 1.10. Apps may drop support for
Django 1.8, 1.9, and 1.10 -- 1.8 support will end in April 2018, approximately 4 months after
the release of 2.0, and the other two versions are now unsupported.
2.1 - Aug. 2018: Drop deprecation shims added in 1.11. This still allows running code that was
deprecation-warning free on 1.11; the shims dropped are for supporting older unsupported
versions.
2.2 - April 2019 (LTS): No deprecation shims dropped. The 2.0 deprecation shims are needed
to help apps maintain compatibility back to 1.11 LTS.
2.3 Features
2.3.1 Complete
Django follows the "Batteries included" philosophy and provides almost everything developers
might want to do "out of the box". Because everything you need is part of the one "product", it
all works seamlessly together, follows consistent design principles, and has extensive and up-
to-date documentation.
2.3.2 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, XML, etc). The site you are currently reading is based on Django!
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.
2.3.3 Secure
8
Django helps developers 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 clickjacking (see Website security for more
details of such attacks).
2.3.4 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,
to name just two).
2.3.5 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).
2.3.6 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 flavours of Linux,
Windows, and Mac OS X. Furthermore, Django is well-supported by many web hosting
providers, who often provide specific infrastructure and documentation for hosting Django sites.
9
3. Django Architecture and Code
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.
10
The URL mapper can also match particular patterns of strings or digits that appear in an 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!
urlpatterns = [
path('admin/', admin.site.urls),
path('catalog/', include('catalog.urls')),
re_path(r'^([0-9]+)/$', views.best),
11
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. We'll talk about these in a later article!
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 book_detail() and can be found in a
module called views (i.e. inside a file named views.py)
Views are the heart of the web application, receiving HTTP requests from web clients and returning
HTTP responses. In between, they marshall 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 HttpRequest object as a parameter
(request) and returns an HttpResponse object. In this case we don't do anything with the request, and
our response simply returns a hard-coded string. We'll show you a request that does something more
interesting in a later section.
def index(request):
# Return HttpResponse
12
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 dirty work of
communicating with the database for you.
The code snippet below shows a very simple Django model for a Team object. The Team class
is derived from the django class models.Model. It defines the team name and team level as character
fields and specifies a maximum number of characters to be stored for each record. The team_level can
be one of several values, so we define it as a choice field and provide a mapping between choices to be
displayed and data to be stored, along with a default value.
# filename: models.py
class Team(models.Model):
team_name = models.CharField(max_length=40)
TEAM_LEVELS = (
13
can support complex statements (for example, you can specify a search on U11 teams that have a team
name that starts with "Fr" or ends with "al").
The code snippet shows a view function (resource handler) for displaying all of our U09 teams. The
line in bold shows how we can use the model query API to filter for all records where
the team_level field has exactly the text 'U09' (note how this criteria is passed to the filter() function as
an argument with the field name and match type separated by a double underscore: team_level__exact).
## filename: views.py
def index(request):
list_teams = Team.objects.filter(team_level__exact="U09")
This function uses the render() function to create the HttpResponse that is sent back to the browser.
This function is a shortcut; it creates an HTML file by combining a specified HTML template and some
data to insert in the template (provided in the variable named "context"). In the next section we show
how the template has the data inserted in it to create the HTML.
The code snippet shows what the HTML template called by the render() function in the previous section
might look like. This template has been written under the assumption that it will have access to a list
variable called youngest_teams when it is rendered (contained in the context variable inside
the render() function above). Inside the HTML skeleton we have an expression that first checks if
14
the youngest_teams variable exists, and then iterates it in a for loop. On each iteration the template
displays each team's team_name value in an <li> element.
## filename: best/templates/best/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Home page</title>
</head>
<body>
{% if youngest_teams %}
<ul>
{% endfor %}
</ul>
{% else %}
{% endif %}
</body>
</html>
15
Forms: HTML Forms are used to collect user data for processing on the server. Django simplifies form
creation, validation, and processing.
User authentication and permissions: Django includes a robust user authentication and permission
system that has been built with security in mind.
Caching: Creating content dynamically is much more computationally intensive (and slow) than
serving static content. Django provides flexible caching so that you can store all or part of a rendered
page so that it doesn't get re-rendered except when necessary.
Administration site: The Django administration site is included by default when you create an app
using the basic skeleton. It makes it trivially easy to provide an admin page for site administrators to
create, edit, and view any data models in your site.
Serialising data: Django makes it easy to serialise and serve your data as XML or JSON. This can be
useful when creating a web service (a website that purely serves data to be consumed by other
applications or sites, and doesn't display anything itself), or when creating a website in which the client-
side code handles all the rendering of data.
4. My Project
4.1 Introduction
To develop the Online Hostel and PG searching website, the work is started by gather information
about the topic. The technology such as software and hardware needed to develop the study are
decided. To gather requirements of this study, discussion is held within supervisor and hostels and
PG owners.
After studying and analyzing the flow of the current system of hostel and PGs, the system
would like the following:
The system proves to be fast accurate convenient, efficient and reliable for the process of reservation.
The online searching system suitable for the hotel; the system could save time, effort in filling and
monitoring.
Hostel and PGs searching system plays a great role and has a potential effect on day to day
performance measures. Due to the rapid change of technology the use of such system has become a
necessity to any given high learning institution for better performance and be used with quite a large
number of users at the same time but it can save time, resources and creates awareness of the evolving
technology.
16
4.2 Goals
The goal of the current system is to develop a Online Hostel and PG Searching website to replace the
manual searching. The purpose of the document is to describe requirements for the Online Hostel and
PG Searching Software that will serve as a foundation for the final product. This document uses written
descriptions as well as various types of modeling diagrams to illustrate the high level structure of the
application. Although some of these diagrams may seem to convey similar information they typically
do so from an alternate perspective. This gives different stakeholders a view of the requirements that
is better suited to their area responsibility.
A web based solution will be delivered so that users the system with their favorite browser. By
designing around a standardized language like PYTHON( Django web framework) the application will
run on the most popular computer platforms connected to the internet will allow peoples and owners
to more easily share information.
Many typical things involved in finding a hostel or a PG will be automated through software
to improve the operational workflow within a facility, for instance Checking the Availability of the
room in particular PG or Hostel. In addition, tasks like Post PG and Hostel details and Drop Messages
will be available within the program to minimize the time that waste in searching on area to area by
walking or by calling.
Admin An admin has the responsibility to look the customer which were added and
also he can access the system he can remove any user which is not genuine
and check the PG or Hostel details request. He can remove the PG or Hostel
according to the requirements.
Person Here the customer can only view the PG and hostel according to the area if a
customer want to add their PG and hostel he can post details of their PG and
hostel also.
System The system refers to the computer hardware and software that controls all
application. Its accepts user input ,display user output, and web server thru
internet.
17
4.3.2 Use Case
Get PG &
Hostel
details
Send
Messages
to admin
Post Hostel
Person and PG
Details
18
Update
Hostel &
PG
Remove
Users
Admin
19
5. Website Overview
20
5.2 Images Section of the Website
In the beginning, the Web was just text, and it was really quite boring. Fortunately, it wasn't too long before
the ability to embed images (and other more interesting types of content) inside web pages was added.
21
5.3 Services Section of Webpage
Trust is a bigger part of selling services. A faulty product can be returned, and flaws are relatively
objective. But with services, customers may worry about what recourse they will have if they’re
unhappy, even if you offer excellent customer service guarantees.
It’s likely that the services page isn’t the first thing potential customers see on your website. Perhaps
they came in through blog posts, or Google searches brought them to your home page. Either way,
they want to know more about you—but that doesn’t necessarily mean they already have a good idea
of what you do. Sure, some visitors have already read your home page and FAQs, but others came in
via social media or a blog post and haven’t read anything else. They chose to click on the services
page because they want to find out more.
Before asking people to dig in to the details of each of your services, give them a top-level view of
what you do and the unique value you offer . This opens the door for further conversation and
establishes the context through which they’ll interpret the rest of the information they read.
22
5.4 Contact Section of the Website
A contact page is a standard web page on a website used to allow the visitor to contact the website owner or
people who are responsible for the maintenance of the site. The page often contains one or more of the
following items:
a mail to link to an e-mail address.
a description of personalia like a (organization) name, address, zip code, residential area, with
sometimes a map indicating a certain physical location and a description or visualization of how to get
there;
a set of visual icons or textual links to social networking services;
a contact form with entries where the visitor can fill in their name, subject and message and send or reset
it.
23
5.5 Sign up Page of the Website
A registration form is a list of fields that a user will input data into and submit to a company or individual.
There are many reasons why you would want a person to fill out a registration form. Companies use
registration forms to sign up customers for subscriptions, services, or other programs or plans.
24
Here is the code of signup page functioning how a signup page function
25
5.6 OTP verification After Signup
After Click on the Signup
When you click on the signup this would redirect to the OTP verification page where your mail get verified.
26
Codes for OTP generation and checking
27
5.7 Login Page of Website
Logins are used by websites, computer applications, and mobile apps. They are a security measure designed
to prevent unauthorized access to confidential data. When a login fails (i.e, the username and password
combination does not match a user account), the user is disallowed access.
28
Here is the code for the login functionality
29
5.8 Forgot password
30
Codes for Forgot Password
31
Here is the code for the
generation of the OTP
Here the 4-digit OTP
generated and stored
in the session for
future use in checking
the OTP
32
5.9 Homepage After Login
When a person click on this it When you here there is page open
redirects to a page where you get where you post there your hostel
the Hostel and PG according to and PG details. By this other
the locality you want and it peoples view your Hostel and PG.
shows PG and hostels for boys
There is also a message box for
and girls
sending message
Log out
By this you were logged
out and redirect to
homepage
33
5.10 GET PG
34
After click on the PG according to Choice of the Area
35
5.11 POST PG Details
36
Code For Post PG details
37
Forms use in the website
Codes used to make forms
1. Log in Form
2. Sign up Form
3. OTP Form
4. Check OTP Form
5. Change Password Form
38
There are more forms which are:
39
Database System
There is database name as Sqlite3 which I used in my project
Codes to make database tables are:
1. User
2. Postmodel
40
5.12 Admin Login Screen
41
5.13 Admin Page After Login
42
5.14 User Details
43
5.15 PG Details in Admin Panel
44
45