Week No: 01 Date 1. Aim of The Program
Week No: 01 Date 1. Aim of The Program
1.
Description:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
</body>
</html>
The <!DOCTYPE html> declaration defines that this document is an HTML5 document
The <html> element is the root element of an HTML page
The <head> element contains meta information about the HTML page
The <title> element specifies a title for the HTML page (which is shown in the browser's title
bar or in the page's tab)
The <body> element defines the document's body, and is a container for all the visible
contents, such as headings, paragraphs, images, hyperlinks, tables, lists, etc.
The <h1> element defines a large heading
The <p> element defines a paragraph
HTML TABLES
Table Cells
Each table cell is defined by a <td> and a </td> tag.
td stands for table data.
Everything between <td> and </td> are the content of the table cell.
Table Rows
Each table row starts with a <tr> and end with a </tr> tag.
tr stands for table row.
Table Headers
When you want your cells to be headers, in those cases use the <th> tag instead of the <td>
tag.
Program Code:
Result analysis
Description/algorithm:
Images are not technically inserted into a web page; images are linked to web pages. The
<img> tag creates a holding space for the referenced image.
The <img> tag is empty, it contains attributes only, and does not have a closing tag.
The <img> tag has two required attributes:
src - Specifies the path to the image
alt - Specifies an alternate text for the image
There are two ways to specify the URL in the src attribute:
1. Absolute URL - Links to an external image that is hosted on another website. Example:
src="https://www.w3schools.com/images/img_girl.jpg".
2. Relative URL - Links to an image that is hosted within the website. Here, the URL does
not include the domain name. If the URL begins without a slash, it will be relative to the
current page. Example: src="img_girl.jpg". If the URL begins with a slash, it will be relative
to the domain. Example: src="/images/img_girl.jpg".
Program Code:
<!DOCTYPE html>
<html>
<body>
<center><h2>Biodata</h2></center>
Output:
Description/algorithm:
To add a background image on an HTML element, use the HTML style attribute and the CSS
background-image property
HTML Lists
HTML lists allow web developers to group a set of related items in lists.
An unordered list starts with the <ul> tag. Each list item starts with the <li> tag.
The list items will be marked with bullets (small black circles) by default.
It can have one of the following values:
Value Description
disc Sets the list item marker to a bullet (default)
circle Sets the list item marker to a circle
square Sets the list item marker to a square
none The list items will not be marked
An ordered list starts with the <ol> tag. Each list item starts with the <li> tag.
The list items will be marked with numbers by default.
The type attribute of the <ol> tag, defines the type of the list item marker:
Type Description
type="1" The list items will be numbered with numbers (default)
type="A" The list items will be numbered with uppercase letters
type="a" The list items will be numbered with lowercase letters
type="I" The list items will be numbered with uppercase roman numbers
type="i" The list items will be numbered with lowercase roman numbers
Program Code:
<body background="C:\Users\jayan\Documents\160120733061\iwt\fd.jpg">
Result analysis
Design a web page to images and in one column and their description in another column
using table.
Description/algorithm:
HTML Links
Links are found in nearly all web pages. Links allow users to click their way from page to
page.
When you move the mouse over a link, the mouse arrow will turn into a little hand.
The HTML <a> tag defines a hyperlink. It has the following syntax:
The link text is the part that will be visible to the reader.
Clicking on the link text, will send the reader to the specified URL address.
By default, the linked page will be displayed in the current browser window. To change this,
you must specify another target for the link.
_self - Default. Opens the document in the same window/tab as it was clicked
Program Code:
<center><h3>Profile Table<he></center>
<table border="3" align="center">
<tr>
<th>S.No</th>
<th>Name</th>
<th>Photo</th>
<th>Profile</th>
</tr>
<tr>
<th>1.</th>
<th>Dwayne Johnson</th>
<th><img src="C:\Users\jayan\Documents\160120733061\iwt\1..jpg" height="100"
width="100"></th>
<td>
<a href="https://en.wikipedia.org/wiki/Dwayne_Johnson">profile link</a>
</td>
</tr>
<tr>
<th>2.</th>
<th>Joe Biden</th>
<th><img src="C:\Users\jayan\Documents\160120733061\iwt\2..jpg" height="100"
width="100"></th>
<td>
<a href="https://en.wikipedia.org/wiki/Joe_Biden">profile link</a>
</td>
</tr>
</table>
Result analysis
A web page is created which contains a table of contents – name, image and profile links.
Html tables are used to create the table with required number of cells and data is filled.
Images are inserted using image tags and source. Profiles links are created using reference
inside the tags.
Description/algorithm:
HTML FORMS
HTML elements gives styles and meaning to a web site. To add interactivity to a web page forms to
be used.
<Form> element:
<form> block level element that defines an interactive part of a web page. All form control
elements like textbox, buttons appear within a <form> element.
Form attributes
1. action: specifies address where form information to be sent.
2. Method: could be GET or POST how form information will be sent.
<input> tag:
• form elements use the <input> tag, with a type="..." attributes to tell which kind of element
it is.
• Input tag attributes
1. Type - specifies type of the input control
2. Name – name of the control input tag has
An <input> element can be displayed in many ways, depending on the type attribute.
<textarea>:
The <textarea> tag defines a multi-line text input control.
The name attribute is needed to reference the form data after the form is submitted (if you omit the
name attribute, no data from the text area will be submitted).
The id attribute is needed to associate the text area with a label.
<select>:
The <select> element is used to create a drop-down list.
The name attribute is needed to reference the form data after the form is submitted (if you omit the
name attribute, no data from the drop-down list will be submitted).
The id attribute is needed to associate the drop-down list with a label.
<!DOCTYPE html>
<html>
<head>
<title>Registration Form</title>
</head>
<body>
<center><h1>Registration Form</h1></center>
<form>
<center>
<table bgcolor="beige" cellspacing="15">
<tr>
<td> Username <font color="red" >* </font>:</td>
<td> <input type="text" placeholder="Enter Username" name="Username" size="30"
required/></td>
</tr>
<tr>
<td> Password <font color="red" >* </font>:</td>
<td> <input type="text" name="Password" placeholder="Enter Password"size="30"
required/></td>
</tr>
<tr>
<td> Confirm Password <font color="red" >* </font>:</td>
<td> <input type="text" name="Confirm Password"placeholder="Reenter Password"
size="30" required/></td>
</tr>
<tr>
<td> Mother's Name : </td>
<td> <input type="text" name="Mother's Name" size="30"/></td>
</tr>
<tr>
<td> Father's Name :</td>
<td> <input type="text" name="Father's Name" size="30"/></td>
</tr>
<tr>
<td> Email <font color="red" >* </font>:</td>
<td> <input type="text" name="Email" placeholder="[email protected]"
size="30" required/></td>
</tr>
<tr>
<td> Phone Number <font color="red" >* </font>:</td>
<td> <input type="text" name="Phone Number" placeholder="XXXXXXXXXX"
size="30" required/></td>
</tr>
<tr>
<td> Gender :</td>
<td>
<input type="radio" name="Gender" value=1/>Male
<input type="radio" name="Gender" value=1/>Female
<input type="radio" name="Gender" value=1/>Other
</td>
<td>
<input type="radio" name="dep" value=1/>CSE
<input type="radio" name="dep" value=1/>EEE
<input type="radio" name="dep" value=1/>BBA
</td>
</tr>
<tr>
<td>
Blood Group :
</td>
<td>
<select name="bloodgroup" id="bloodgroup" >
<option value="A+">A+</option>
<option value="A-">A-</option>
<option value="B+">B+</option>
<option value="B-">B-</option>
<option value="AB+">AB+</option>
<option value="AB-">AB-</option>
<option value="O+">O+</option>
<option value="O-">O-</option>
</select>
</td>
</tr>
<tr>
<td> Course :</td>
<td>
<input type="checkbox" name="C" value=c/>C
<input type="checkbox" name="C++" value=c++/>C++
<input type="checkbox" name="Java" value=java/>Java
<input type="checkbox" name="AI" value=ai/>AI
<input type="checkbox" name="ML" value=ml/>ML
</td>
</tr>
<tr>
<td> Photo : </td>
<td><input type="file" name="image"/></td>
</tr> <tr></tr>
Output:
A registration form is created with various type of elements. Table tags are used to create two
columns, one of which has details and the other has inputs that are accepted by user. A simple text
type inputs are used for entering details and required attribute is used to make the credentials
mandatory. Radio buttons and checkboxes are used for choosing details. Address is taken in textarea
for multiple line entry. Select, Photo, Submit and Reset are the types of input are used.
1.
Description:
CSS Padding
The CSS padding property defines a padding (space) between the text and the border.
CSS Border
The CSS border property defines a border around an HTML element.
CSS Margin
The CSS margin property defines a margin (space) outside the border.
The div tag is known as Division tag. The div tag is used in HTML to make divisions of content in
the web page like (text, images, header, footer, navigation bar, etc). Div tag has both open(<div>)
and closing (</div>) tag and it is mandatory to close the tag. The Div is the most usable tag in web
development because it helps us to separate out data in the web page and we can create a particular
section for particular data or function in the web pages.
<html>
<head>
<title>Chess Board</title>
<style type="text/css">
.chessboard{
width:640px;
height:640px;
margin:20px;
border:7px solid black;
}
.black{
float: left;
width: 80px;
height: 80px;
background-color:grey;
font-size:50px;
text-align:center;
display: table-cell;
vertical-align:middle;
}
.white {
float: left;
width: 80px;
height: 80px;
background-color: white;
font-size:50px;
text-align:center;
display: table-cell;
vertical-align:middle;
}
</style>
</head>
<center><body>
<div class="chessboard">
<! 1st row>
<div class="white">♜</div>
<div class="black">♞</div>
<div class="white">♝</div>
<div class="black">♛</div>
<div class="white">♚</div>
<div class="black">♝</div>
<div class="white">♞</div>
<div class="black">♜</div>
<!-- 2nd -->
<div class="black">♝</div>
<div class="white">♝</div>
</body></center>
</html>
Output:
A chess board is created. Chess board and each black and white squares are designed using inline
css style tag. Display attribute is used to make each square a table cell. Division tags are used to
create checks.
Description/algorithm:
FRAMES:
Frames are used to divide a browser window into multiple sections where each section loads a
separate html document.
<FRAMESET>
The <frameset> tag replaces the <body> element in frameset documents.
The <frameset> tag defines how to divide the window into frames.
FRAMESET ATTRIBUTES
<frameset borders=“5”>
the width of the border of each frame in pixels
<frame src="URL">
Specifies which HTML document should be displayed
Frame attributes:
<frame name="name">
Names the frame, or region, so it may be targeted by other frames
<frame scrolling=VALUE>
Sets whether the frame has a scrollbar; value may equal "yes," "no," or "auto." The default, as in
ordinary documents, is auto.
<frame marginwidth=#>
Defines the space between left and right margins for the frame and frame content; must be equal to
or greater than 1
<frame marginheight=#>
Defines the space between the top and bottom margins for the frame and frame content; must be
equal to or greater than 1
banner.html
<html>
<body >
<img src="iwwt.jpg" alt="image" width="1600" height="300">
</body>
</html>
navigation.html
<html>
<body style="background-color:powderblue;">
<center><h1>CONTENTS</h1></center>
<a href="file:///C:/Users/jayan/Documents/160120733061/iwt/tble.htm"
target="3"><h3>TIME TABLE</h3></a><br/>
<a href="file:///C:/Users/jayan/Documents/160120733061/iwt/menu.htm"
target="3"><h3>HOTEL MENU</h3></a><br/>
<a href="file:///C:/Users/jayan/Documents/160120733061/iwt/bio.htm" target="3"><h3>BIO
DATA</h3></a><br/>
<a href="file:///C:/Users/jayan/Documents/160120733061/iwt/profiles.htm"
target="3"><h3>PROFILES</h3></a><br/>
<a href="file:///C:/Users/jayan/Documents/160120733061/iwt/registration%20form.html"
target="3"><h3>REGISTRATION FORM</h3></a><br/>
<a href="file:///C:/Users/jayan/Documents/160120733061/iwt/chess.html"
target="3"><h3>CHESS BOARD</h3></a><br/>
</body>
</html>
content.html
<html>
<body>
<h1>Content Page</h1>
</body>
</html>
Frames.html
<html>
<head>
<title>Frames</title>
</head>
</html>
Result analysis:
A html page is created with a banner, navigation and content page. The navigation page contains
references to pages that are displayed in the content page.
Description:
Css colours:
CSS uses color values to specify a color. Typically, these are used to set a color either for the
foreground of an element (i.e., its text) or for the background of the element. They can also
be used to affect the color of borders and other decorative effects.
You can specify your color values in various formats.
CSS Comments:
Many times, you may need to put additional comments in your style sheet blocks. So, it is
very easy to comment any part in the style sheet. You can simply put your comments inside
/*.....this is a comment in style sheet .... */.
You can use /* .... */ to comment multi-line blocks in similar way you do in C and C++
programming languages.
The <link> element can be used to include an external stylesheet file in your HTML document.
An external style sheet is a separate text file with .css extension. You define all the Style
rules within this text file and then you can include this file in any HTML document using <link>
element.
Absolute Units: Absolute units as the name suggest are fixed in nature.
px: Pixel is a small unit but still visible and is relative to the viewing device.
cm: Centimeters, 1cm=37.8px
mm: millimeters, is a smaller unit as compared to cm, 1 mm=1/10th of 1cm.
in: inches, is a large unit compared to pixels, 1in=96px
pc: pica is a typographic unit, 1pc=1/6th of 1in
pt: Points is the smallest unit of measure, 1pt=1/72 of 1in
Program Code:
Html:
<!doctype html>
<html>
<head>
<title>Chaithanya Barathi Institute of Technology</title>
<link rel="stylesheet" href="css/style.css"/>
<style>
body, html {
height: 100%;
margin: 0;
}
.bg {
/* The image used */
background-image: url("images/bcg.jpg");
/* Full height */
height: 100%;
</style>
</head>
<body>
<div class="bg">
<section>
<nav>
</section>
<!--main-content-->
<div class="home-content">
<!--text-->
<div class="home-text" >
<!--login-btn-->
</div>
<!--img-->
</div>
</div>
</div>
</body>
</html>
Style.css:
.logo img{
height: 80px;
}
nav{
display: flex;
align-items: center;
justify-content: space-around;
padding: 0px 30px;
background-color:#fff;
box-shadow: 2px 2px 20px rgba(255, 151, 103, 0.164);
z-index: 1;
width:100%;
position: fixed;
left: 0px;
top: 0px;
}
nav ul{
display: flex;
margin:0px;
padding: 0px;
}
nav ul li a{
height:40px;
line-height: 43px;
margin: 8px;
padding: 0px 10px;
display: flex;
font-size: 0.9rem;
text-transform: uppercase;
font-weight: 400;
color:#111;
letter-spacing: 1px;
transition: 0.4s ease-in-out;
}
.active{
background-color: #7c3b41;
.home-content{
display: flex;
justify-content: space-around;
align-items: center;
position: absolute;
left: 50%;
top:50%;
transform: translate(-50%,-50%);
width:90%;
}
.home-img{
width:500px;
height:400px;
margin:20px;
}
.home-img img{
width: 100%;
height: 100%;
object-fit: contain;
object-position: center;
}
.home-text{
width:500px;
margin: 20px;
}
Result analysis:
A student portal is designed using html and css. Various fields are given in the page which can be
directed to other html pages. Different style attributes are used to improve the appearance of html
page. A different file is used to define style selectors and is finally linked to the html page.
1.
Description:
XML Elements
• Following are the types of XML elements
1. Text only elements: if element has only text data can be defined with data type #PCDATA inside
parenthesis.
<!ELEMENT element-name (#PCDATA)>
2. Child only elements:Elements with one or more children are declared with the name of the
children elements inside parentheses:
<!ELEMENT element-name (child1,child2,...)>
4. Empty element:Empty elements are declared with the category keyword EMPTY:
<!ELEMENT element-name EMPTY>
Empty element may contain attributes.
5. Any element:Elements declared with the category keyword ANY, can contain any
combination of parsable data:
DTD:
<!DOCTYPE stock [
]>
XML:
<stock>
<new-car>
<model>Fiat Panda</model>
<price>12000</price>
</new-car>
<used-car>
<model>Fiat Bravo</model>
<price>4000</price>
<mileage>1000</mileage>
<condition>Good</condition>
</used-car>
<used-car>
<model>Ferrari</model>
<price>400000</price>
<mileage>100</mileage>
</used-car>
</stock>
Result analysis:
A dtd is designed for given xml. Document type is defined. Each selector is given in the form of
Element. The elements with only text is given as PCDATA. Child elements are mentioned inside
parenthesis.
Aim of the program: Designing DTD and XML for the bibliography of a book.
Description:
Occurrences of elements:
Declaring Attributes
An attribute declaration has the following syntax:
<!ATTLIST element-name attribute-name attribute-datatype default-value>DTD
example:<!ATTLIST payment type CDATA "check">
Attributes:
Type Description:
Value Explanation
value of default value of the attribute:
Program Code:
DTD:
XML:
<bibliography>
<book ISBN="ABC123" price="1200">
<title>IWT</title>
<author>iwt reader</author>
<publisher>XYZ</publisher>
<year>2003</year>
<section>
<title>IWT</title>
<content>
name
<i>user</i>
</content>
</section>
</book>
</bibliography>
Result analysis:
A DTD and an XML is designed for the bibliography of a book. Attributes are defined and their
type is mentioned. Occurrences of an attribute is determined using various syntaxes. Attribute list is
used.
Description:
#REQUIRED:
Syntax:
<!ATTLIST element-name attribute-name attribute-type #REQUIRED>Example
DTD: <!ATTLIST person number CDATA #REQUIRED>Valid XML: <person number="5677" />
Invalid XML: <person />
Use the #REQUIRED keyword if you don't have an option for a default
value, but still want to force the attribute to be present.
#IMPLIED;
Syntax:
<!ATTLIST element-name attribute-name attribute-type #IMPLIED>Example
DTD: <!ATTLIST contact fax CDATA #IMPLIED>
Valid XML: <contact fax="555-667788" />
Valid XML: <contact />
Use the #IMPLIED keyword if you don't want to force the author to
include an attribute, and you don't have an option for a default value.
#FIXED:
Syntax:
<!ATTLIST element-name attribute-name attribute-type #FIXED "value">Example
DTD: <!ATTLIST sender company CDATA #FIXED “CBIT">Valid XML: <sender company=
“CBIT" />
Invalid XML:<sender company=“CSE" />
Use the #FIXED keyword when you want an attribute to have a fixed
value without allowing the author to change it. If an author includes
another value, the XML parser will return an error.
Syntax:
<!ATTLIST element-name attribute-name (en1|en2|..) default-value>Example
DTD: <!ATTLIST payment type (check|cash) "cash">
XML example:
<payment type="check" /> or
<payment type="cash" />
Use enumerated attribute values when you want the attribute value to be one of a fixed set of legal
values.
DTD:
<?xml version="1.0"?>
<!DOCTYPE collection[
<!ELEMENT collection (description,recipe*)>
<!ELEMENT description ANY>
<!ELEMENT recipe (title,ingredient*,preparation,comment?,nutrition)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT ingredient (ingredient*,preparation)?>
<!ATTLIST ingredient name CDATA #REQUIRED
amount CDATA #IMPLIED
unit CDATA #IMPLIED>
<!ELEMENT preparation (step*)>
<!ELEMENT step (#PCDATA)>
<!ELEMENT comment (#PCDATA)>
<!ELEMENT nutrition EMPTY>
<!ATTLIST nutrition protein CDATA #REQUIRED
carbohydrates CDATA #REQUIRED
fat CDATA #REQUIRED
calories CDATA #REQUIRED
alcohol CDATA #IMPLIED>
]>
XML:
<collection>
<description>
Some recipes used for the xml tutorial.
</description>
<recipe>
<title>Fried Rice</title>
<ingredient name="rice" amount="2" unit="4"/>
<ingredient name="salt" amount="0.5" unit="3"/>
<preparation>
<step>Preheat a large skillet or wok to medium heat. Pour sesame oil in the bottom. </step>
<step>Slide the onion, peas and carrots to the side, and pour the beaten eggs onto the other side.
Using a spatula, scramble the eggs.</step>
<step>Add the rice to the veggie and egg mixture. Pour the soy sauce on top.</step>
</preparation>
<comment>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Molestiae ipsum perferendis ducimus
corrupti est eius. Repudiandae nihil nisi perspiciatis consequatur culpa suscipit laborum velit
corporis, perferendis dolorum modi ipsam! Rerum velit reiciendis fugiat beatae. Maxime mollitia
eaque ea nam voluptatem libero, nobis accusantium pariatur sed aliquid odit minima quae officiis.
</comment>
<nutrition protein="4.7g" carbohydrates="31g" calories="163" alcohol="0" fat="2.3g"/>
</recipe>
</collection>
Result analysis:
A DTD and XML is designed for preparation of a recipe. Title, ingredients, steps are defined.
Multiple steps are used to describe the process. Comment and nutrition are also added.
1.
Description:
XML Schema is commonly known as XML Schema Definition (XSD). It is used to describe and
validate the structure and the content of XML data. XML schema defines the elements, attributes
and data types. Schema element supports Namespaces. It is similar to a database schema that
describes the data in a database
An XML XSD is kept in a separate document and then the document can be linked to an XML
document to use it.
<Schema> Element
XSD Element:
Simple Element is an XML element which can only have text. It can not contain any attribute.
Syntax: <xs:element name = "element-name" type = "element-type"/>
Default Value:
A Simple Element can have a default value assigned. Default values are used in case an element
does not have any text.
<xs:element name = "grade" type = "xs:string" default = "NA" />
Fixed Value:
Simple Element can have fix value assigend. In case, fixed value is assigned element can not have
any text.
<xs:element name = "class" type = "xs:string" fixed = "1" />
Attributes:
Attribute represents the attribute of an XML element. XSD defines it as a simple type.
Syntax: <xs:attribute name = "attribute-name" type = "attribute-type"/>
Default Value:
Attribute can have a default value assigned to it. Default value is used in case the attribute has no
value.
<xs:attribute name = "grade" type = "xs:string" default = "NA" />
Fixed Value
Attribute can have a fix value assigned. In case a fixed value is assigned, then the element can not
have any value.
<xs:attribute name = "class" type = "xs:string" fixed = "1" />
XSD:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xs:element name="stock">
<xs:complexType>
<xs:choice>
<xs:element name="new-car">
<xs:complexType>
<xs:sequence>
<xs:element name="model"></xs:element>
<xs:element name="price"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="used-car" maxOccurs="unbounded">
<xs:complexType>
<xs:choice>
<xs:element name="model"></xs:element>
<xs:element name="price"></xs:element>
<xs:element name="mileage"></xs:element>
<xs:element name="condition"></xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
XML:
Result analysis:
A xsd is designed for given xml. Document type is defined. Elements are defined as complextype
and sequence.
Aim of the program: Designing XSD and XML for the bibliography of a book.
Description:
Complex Element is an XML element which can contain other elements and/or attributes. We can
create a complex element in two ways −
Define a complex type and then create an element using the type attribute
XSD:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="bibliography">
<xs:complexType>
<xs:sequence>
<xs:element name="book" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"></xs:element>
<xs:element name="autrhor" type="xs:string"></xs:element>
<xs:element name="publisher" type="xs:string"></xs:element>
<xs:element name="year" type="xs:integer"></xs:element>
<xs:element name="content"></xs:element>
</xs:sequence>
<xs:attribute name="ISBN" type="xs:string"></xs:attribute>
<xs:attribute name="price" type="xs:integer"></xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
XML:
<?xml version="1.0"?>
<bibliography
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:SchemaLocation="2i.xsd">
<book ISBN="ABC123" price="1200">
<title>INTERNET</title>
<author>Kash Cont</author>
<publisher>Xander</publisher>
<year>2003</year>
<section>
<title>INTERNET</title>
<content>
name
<i>user</i>
</content>
</section>
</book>
</bibliography>
Result analysis:
A XSD and an XML is designed for the bibliography of a book. Attributes are defined and their type
is mentioned. Occurrences of an attribute is determined using various syntaxes.
Description:
Complex Text-only Element can only have text and attribute, but no content. See the following
example − <marks grade = "A" >90</student>
We can declare Complex Text-only elements using the following methods −
Use SimpleContent
The <xs:string> data type can take characters, line feeds, carriage returns, and tab characters. The
XML processor does not replace line feeds, carriage returns, and tab characters in the content with
space and keep them intact. For example, multiple spaces or tabs are preserved during display.
Complex Mix Element can have text and attribute and elements. See the following example −
Use mixed=true
Define complexType with attribute "mixed" set to true. "mixed" attribute allow to have character
data between elements.
Indicators control the way how elements are to be organized in an XML document. There are seven
types of indicators, falling into three broad categories.
Order Indicators
Occurence Indicators
Group Indicators
Program Code:
XSD:
<?xml version="1.0"?>
<collection
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:SchemaLocation="3i.xsd">
<description>
Some recipes used for the xml tutorial.
</description>
<recipe>
<title>Fried Rice</title>
<ingredient name="rice" amount="2" unit="4"/>
<ingredient name="salt" amount="0.5" unit="3"/>
<preparation>
<step>Preheat a large skillet or wok to medium heat. Pour sesame oil in the bottom. </step>
<step>Slide the onion, peas and carrots to the side, and pour the beaten eggs onto the other side.
Using a spatula, scramble the eggs.</step>
<step>Add the rice to the veggie and egg mixture. Pour the soy sauce on top.</step>
</preparation>
<comment>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Molestiae ipsum perferendis ducimus
corrupti est eius. Repudiandae nihil nisi perspiciatis consequatur culpa suscipit laborum velit
corporis, perferendis dolorum modi ipsam! Rerum velit reiciendis fugiat beatae. Maxime mollitia
eaque ea nam voluptatem libero, nobis accusantium pariatur sed aliquid odit minima quae officiis.
</comment>
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xs:element name="collection">
<xs:complexType>
<xs:sequence>
<xs:element name="description" type="xs:string"></xs:element>
<xs:element name="recipe">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"></xs:element>
<xs:element name="ingredients">
<xs:complexType>
<xs:attribute name="name" type="xs:string"></xs:attribute>
<xs:attribute name="amount" type="xs:integer"></xs:attribute>
<xs:attribute name="unit" type="xs:integer"></xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="preparation">
<xs:complexType>
<xs:sequence>
<xs:sequence>
<xs:element name="step" type="xs:string" maxOccurs="3"></xs:element>
</xs:sequence>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="comment" type="xs:string"></xs:element>
<xs:element name="nutrition">
<xs:complexType>
<xs:attribute name="protein" type="xs:string"></xs:attribute>
<xs:attribute name="carbohydrates" type="xs:string"></xs:attribute>
<xs:attribute name="calories" type="xs:string"></xs:attribute>
<xs:attribute name="alcohol" type="xs:string"></xs:attribute>
<xs:attribute name="fat" type="xs:string"></xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Result analysis:
A XSD and XML is designed for preparation of a recipe. Title, ingredients, steps are defined.
Multiple steps are used to describe the process. Comment and nutrition are also added.
1.
Description:
Scripts can be placed in the <body>, or in the <head> section of an HTML page, or in both.
JavaScript in <head>
In this example, a JavaScript function is placed in the <head> section of an HTML page.
JavaScript Identifiers
Identifiers can be short names (like x and y) or more descriptive names (age, sum, totalVolume).
The general rules for constructing names for variables (unique identifiers) are:
JavaScript Variables
JavaScript uses the keywords var, let and const to declare variables.
<html>
<head>
<title>Multiplication Table</title>
<script type="text/javascript">
createT(rows, cols);
for(i=1;i<=rows;i++)
{
output = output + "<tr>";
for(j=1;j<=cols;j++)
output = output + "<td>" + i*j + "</td>";
output = output + "</tr>";
j = 1;
}
document.write(output);
}
</script>
</head>
<body>
</body>
</html>
Result analysis:
Multiplication table is created which contains provided number of rows and columns where each
cell of table contains the product of row and column elements.
Description:
JavaScript Operators:
if statement
The if statement is the fundamental control statement that allows JavaScript to make decisions and
execute statements conditionally.
if...else statement
The 'if...else' statement is the next form of control statement that allows JavaScript to execute
statements in a more controlled way.
The loop initialization where we initialize our counter to a starting value. The initialization
statement is executed before the loop begins.
The test statement which will test if a given condition is true or not. If the condition is true, then the
code given inside the loop will be executed, otherwise the control will come out of the loop.
The iteration statement where you can increase or decrease your counter.
<html>
<head>
<style>.container {
border-radius: 20px;
position: absolute;
top: 55%;
left: 50%;
width: 450px;
height: 400px;
.keys {
display: grid;
grid-gap: 10px;
padding: 10px;
margin:auto;
.button {
height: 60px;
padding: 5px;
background-color: #fff;
border-radius: 3px;
font-size: 2rem;
color: #333;
.operator {
color: #fff;
background-color: #a19a82;
.clear {
background-color: #a88283;
border-color: #857c7c;
text-align: center;
color: #fff;
font-size: 20px;
width: 220px;
height: 62px;
padding: 20px;
margin: auto;
margin-bottom: 10px;
.equal-sign {
background-color: #466471;
border-color: #383b3c;
color: #fff;
.screen{
justify-content: left;
color: black;
font-size: medium;
width: 100%;
height: 50%;
cursor: default;
padding: 20px;
padding-left: 40%;
margin: auto;
margin-bottom: 10px;
}</style>
<script>
function display(val){
document.getElementById('result').value += val
return val
}
function solve(){
let x = document.getElementById('result').value
let y = eval(x);
document.getElementById('result').value = y
return y
}
function clearScreen(){
document.getElementById('result').value = '
}
</script>
</head>
<body>
<h1 style="text-align:center">Calculator</h1>
<div class="container">
<br>
<table>
<tr>
<td colspan="3"><input type='text' id='result' class ='screen' style="text-align: right;"></td>
<td><input type='button' value = 'Clear' onclick="clearScreen()" class="clear"/></td>
</tr>
Output:
Result analysis:
A simple calculator is created with simple operators, clear bar and an equating button along with a
screen.
Description/algorithm:
Arrays
• An array is a special variable, which can hold more
than one value, at a time.
• Defined in two ways
1. var color = ["red", "yellow", "green", "blue"];
2. var color =new Array("red", "yellow", "green", "blue");
Using innerHTML
Using document.write()
The id attribute defines the HTML element. The innerHTML property defines the HTML content.
Using document.write() after an HTML document is loaded, will delete all existing HTML.
The document.write() method should only be used for testing.
Using window.alert()
In JavaScript, the window object is the global scope object, that means that variables, properties,
and methods by default belong to the window object. This also means that specifying the window
keyword is optional.
External JavaScript
To use an external script, put the name of the script file in the src (source) attribute of a <script> tag
<html>
<head>
<title>Pizza form</title>
</head>
<body>
let a = document.getElementById("cp").value;
let b = document.getElementById("pp").value;
let c = document.getElementById("vp").value;
let t = a*100 + b*80 + c*70;
document.getElementById("tot").innerHTML=t;
}
function conf() {
alert("Order confirmed!");
}
function canc() {
alert("Order canceled!");
}
</script>
<button onclick="conf()">Confirm</button>
<button onclick="canc()">Cancel</button>
</body>
</html>
Result analysis:
A pizza order form is created which takes input the quantities of items and total cost is displayed.
The order can be confirmed or cancled.
1.
To validate an email.
Description:
JavaScript Regex
In JavaScript, a Regular Expression (RegEx) is an object that describes a sequence of characters used for
defining a search pattern.
MetaCharacters
Metacharacters are characters that are interpreted in a special way by a RegEx engine. Here's a list of
metacharacters:
[] . ^ $ * + ? {} () \ |
[] - Square brackets: Square brackets specify a set of characters you wish to match.
You can complement (invert) the character set by using caret ^ symbol at the start of a square-
bracket.
+ - Plus: The plus symbol + matches one or more occurrences of the pattern left to it.
? - Question Mark: The question mark symbol ? matches zero or one occurrence of the pattern left to it.
{} - Braces: Consider this code: {n,m}. This means at least n, and at most m repetitions of the pattern left
to it.
()- Group: Parentheses () is used to group sub-patterns. For example, (a|b|c)xz match any string that
matches either a or b or c followed by xz
<html>
<head>
</head>
<body>
<script type="text/javascript">
function ValidateEmail(input)
{
var e =document.getElementById("email").value;
var y =/^[a-z]{1,20}\d{2}\@[a-z]{2,10}\.[a-z]{3}$/;
if(e.match(y)){
alert("Valid email!");
}
else
{
alert("Invalid email!");
}
}
</script>
</body>
</html>
Output:
Email is validated using regular expression in javascript. Input data is validated by storing it in a
variable.
Description:
\ - Backslash
Backslash \ is used to escape various characters including all metacharacters. For example,
\$a match if a string contains $ followed by a. Here, $ is not interpreted by a RegEx engine in a special
way.
Special Sequences
Special sequences make commonly used patterns easier to write. Here's a list of special
sequences:
\B - Opposite of \b. Matches if the specified characters are not at the beginning or end of a
word.
<!DOCTYPE html>
<html>
<head>
<title>Registration Form</title>
<script>
function fun(){
var nam=document.getElementById("Username").value;
if(nam==null||nam.length<8)
{alert("Enter username with minimum 8 characters") }
var p1=document.getElementById("Password").value;
var p2=document.getElementById("ConfirmPassword").value;
var v=/^[A-Za-z]\w{7,14}$/;
var t=/\W+/;
var d=/\d+/;
if(!(p1.match(v)||p1.match(t)||p1.match(d)))
alert("Invalid password!");
if(p1!=p2)
alert("Password is'nt same");
var e =document.getElementById("email").value;
var y =/^[a-z]{1,20}\d{2}\@[a-z]{2,10}\.[a-z]{3}$/;
if(!e.match(y))
alert("Invalid email!");
var n=document.getElementById("PhoneNumber").value;
if(n.length<8)
alert("Invalid phone number");
var d1=document.getElementById("dd").value;
var x=/^\d{2}\/\d{2}\/\d{4}/;
if(!d1.match(x))
alert("Invalid date!");
}
</script>
</head>
<body>
<center><h1>Registration Form</h1></center>
<form onsubmit="fun()">
<center>
<table bgcolor="beige" cellspacing="15">
<tr>
<td> Username :</td>
<td> <input type="text" placeholder="Enter Username" id="Username" size="30" /></td>
</tr>
<tr>
<td> Password :</td>
<td> <input type="text" id="Password" placeholder="Enter Password"size="30" /></td>
</tr>
<tr>
<td> Confirm Password :</td>
<td>
<input type="radio" name="dep" value=1/>CSE
<input type="radio" name="dep" value=1/>EEE
<input type="radio" name="dep" value=1/>BBA
</td>
</tr>
<tr>
<td>
Blood Group :
</td>
<td>
<select name="bloodgroup" id="bloodgroup" >
<option value="A+">A+</option>
<option value="A-">A-</option>
<td>
<input type="checkbox" name="C" value=c/>C
<input type="checkbox" name="C++" value=c++/>C++
<input type="checkbox" name="Java" value=java/>Java
<input type="checkbox" name="AI" value=ai/>AI
<input type="checkbox" name="ML" value=ml/>ML
</td>
</tr>
<tr>
<td> Photo : </td>
<td><input type="file" name="image"/></td>
</tr> <tr></tr>
<tr>
Inputs from a registration form are validated using regular expression in javascript. Input data is
validated by storing it in a variable.
1.
Description:
Javascript is also used to make XHTML document dynamic after the document being displayed by
browser.
• By using javascript we can change tag attributes, tag content or css properties of an xhtml
elements
• Content of elements are changed dynamically i.e changes can be made after the document has
been being displayed.
• By using java script we can change the content of the different elements document like content
of text box and content of the table dynamically.
• Each table element contains a rows array and methods for inserting and deleting rows:
insertRow() and deleteRow().
• Each tr element contains a cells array and methods forinserting and deleting cells: insertCell()
and deleteCell().
With this document object model javascripts can change static to dynamic and change style of the
html page.
• Java script uses document object to access and manipulate any html element.
<html>
<head>
<script type="text/javascript">
</script>
<body>
<hr>
<form name="formName">
<br />
<br />
<center>
</center>
<hr>
<table id="tblPeople" border="1">
<tr>
<th>First Name</th>
<th>Middle Name</th>
<th>Last Name</th>
</tr>
</table>
</form>
</body>
</html>
Result analysis:
A dynamic table is created which takes the values provided through the text inputs using onclick
event.
Description:
Positioning elements
• By default, elements flow one after another in the same order as they appear in the HTML source,
with each element having a size and position that depends on the type of element, the contents of the
element, and the display context for the element as it will render on the page.
• It usually involves using JavaScript to change a positioning style properties of an HTML elements.
position, top, left are the three properties that dictate the position of the elements.
• position specifies the reference point for the placement of the elements.
• top and left specify the distance from top and left of reference point where element is to appear.
• absolute, relative and static are the three possible values for the position
property.
Absolute positioning
• A element can be placed at specific position in the document using absolute value for the position
styling property
• With absolute positioning elements are placed without regard to the positions of other elements.
For example, if you want place an image 100 pixels from the top and 100 pixels from the left of the
documentdisplay window, it can be placed as following statements:
<img src="earth.jpg" style="position:absolute; left:100px; top:100px" />
• Can be used superimpose text over the ordinary text to create effect similar that watermark on
page.
Relative positioning
• The element is positioned relative to its normal position, so "left:20" adds 20 pixels to the element's
LEFT position. • Make the text superscript and subscript • Default positioning is static
Moving elements
• Xhtml element whose position property is set to either absolute or relative can be moved.
• Change the left and top values also move the element to a specified position.
<html>
<head>
function moveIt(mov,newTop,newLeft)
{
var x=document.getElementById(mov).style;
x.top=newTop+"px";
x.left=newLeft+"px";
}
</script>
<body>
<form action="">
<p>
<label>
x coordinate:
<br/>
<hr>
<label>
y coordinate:
</p>
</form>
</div>
</body>
</html>
Result analysis:
When a mouse is placed over a text, change text color to green when mouse moved out from text
change text color to Red.
Description:
- element.addEventListener(eventobject, funtionname)
Program Code:
<!DOCTYPE html>
<html>
<body>
<h1 onmousedown="style.color='green'"
onmouseup="style.color='red'">Text</h1>
</body>
</html>
Output:
Result analysis:
When the mouse is moved on the screen display the mouse coordinates(X and Y coordinates).
Description:
• Event is a notification about the something happened on browser due to user actions.
• Every event that generated on XHTML document creates an event object. This object has
information about the event.
• A mouse click event has MouseEvent interface, which has two properties that provides
geometric coordinates of the position of the element in the display that created the event.
• These coordinates are relative to the upper left corner of the browser display window.
You can put your validation, warning etc against this event
type.
This event occurs when you try to submit a form. So you can put your form validation against this
event type.
onReset event:
<!DOCTYPE html>
<html>
<body>
<th>Click inside table to get the x (horizontal) and y (vertical) coordinates of the mouse pointer
when it was clicked.</th>
</table>
<p id="demo"></p>
<script>
function showCoords(event) {
var x = event.clientX;
var y = event.clientY;
document.getElementById("demo").innerHTML = coords;
}
</script>
Output:
Result analysis:
The coordinates of the position are generated while the mouse moves through out the specified area.
Installation of Django
1.
Description:
# installation of pip
sudo apt-get install python3-pip
#install virtual env
sudo pip3 install virtualenv
#create virtual environment
virtualenv Demo
# activate virtual Demo
cd Demo/bin - go to folder Demo/bin
source activate
# django installation
sudo apt install python3-django
#check django version
sudo django-admin --version
#create django project
sudo django-admin startproject myproject
# run server
sudo python3 manage.py runserver
Procedure:
Result analysis:
Django is successfully installed, virtual environment is created, project is created and run
successfully.
Description:
1. init .py: if any folder contains this file will be considered as a python package.
2. settings.py: all project related settings and configurations will be specified like database
configurations, installed apps and middleware configurations.
3. urls.py: specifies what are the urls are required to access particular page in web applications
4. wsgi.py: web server gateway interface. Used when application is deployed in online web servers.
5. asgi.py: Asynchronous server gateway interface. Communicates with web server and web
application.
Program code:
Urls.py
urlpatterns = [
path('admin/', admin.site.urls),url(r'^greetings/',views.display),
]
views.py
settimgs.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles', 'wApp1'
]
Result analysis:
Aim of the program: To create virtual evnvironment for django and develop django application to
display current date and time.
Description:
The datetime module supplies classes for manipulating dates and times.
While date and time arithmetic is supported, the focus of the implementation is on efficient attribute
extraction for output formatting and manipulation.
Activity1- settings.py
Activity2- views.py
Activity3- urls.py
Activity4
Start server: python manage.py runserver
Send request: http://127.0.0.1:8000/
Program code:
Urls.py
urlpatterns = [
path('admin/', admin.site.urls),url(r'^date/',views.d),
]
date=datetime.datetime.now()
#display time
s='<h1>The Current Date and Time is :'+str(date)+'</h1>'
return HttpResponse(s)
Output:
Result analysis:
Description:
Creating view:
● First, we import the class HttpResponse from the django.http module, along with Python’s
datetime library.
● Next, we define a function called. This is the view function. Each view function takes an
HttpRequest object as its first parameter, which is typically named request.
● The view returns an HttpResponse object that contains the generated response. Each view
function is responsible for returning an HttpResponse object.
Program code:
views.py
def d(request):
date=datetime.datetime.now()
#display time
s='<h1>The Current Date and Time is :'+str(date)+'</h1>'
return HttpResponse(s)
urlpatterns = [
path('admin/', admin.site.urls),url(r'^greetings/',views.display)url(r'^date/',views.d),
]
Output:
Result analysis:
Multiple views are successfully created by defining multiple functions in views.py. Hence multiple
urls are returned when we run the server.
1.
Aim of the program: To develop an application to wish your friend based on the time like good
morning, good afternoon and good evening using templates and also display an image in the same
application using static folder.
Description:
Django Templates
Django provides a convenient way to generate dynamic HTML pages by using its template system.
A template consists of static parts of the desired HTML output as well as some special syntax
describing how dynamic content will be inserted.
Tags
In a template, Tags provide arbitrary logic in the rendering process. For example, a tag can output
content, serve as a control structure e.g. an "if" statement or a "for" loop, grab content from a
database etc.
Static files
Static files include stuff like CSS, JavaScript and images that you may want to serve alongside your
site.
Django also provides a mechanism for collecting static files into one place so that they can be
served easily. Using the collectstatic command, Django looks for all static files in your apps and
collects them wherever you told it to, i.e. the STATIC_ROOT. In our case, we are telling Django
that when we run python manage.py collectstatic, gather all static files into a folder called staticfiles
in our project root directory. This feature is very handy for serving static files, especially in
production settings.
Program code:
wish.html:
<html>
<head>
<title>Greeting Message using JavaScript</title>
</head>
<body>
<label id="lblGreetings"></label>
<p>{% load static %}
<img src="{%static 'image/wish.jpg' %}"/></p>
</p>
</body>
<script>
var myDate = new Date();
var hrs = myDate.getHours();
document.getElementById('lblGreetings').innerHTML =
'<b>' + greet + '</b>';
</script>
</html>
Views.py:
from django.shortcuts import render
from django.http import HttpResponse
from django.template import loader
# Create your views here.
#from django.http import HttpResponse
def G(request):
template = loader.get_template('wish.html') # getting our template
return HttpResponse(template.render())
Output:
Result analysis:
An application to wish your friend based on the time like good morning, good afternoon and good
evening using templates and also image is displayed using static folder in same application.
1.
Description:
Django Forms
Forms are basically used for taking input from the user in some manner and using that information
for logical operations on databases. For example, Registering a user by taking input as his name,
email, password, etc.
Django maps the fields defined in Django forms into HTML input fields. 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
Syntax:
from django import forms
class FormName(forms.Form):
# each field would be mapped as an input field in HTML
field_name = forms.Field(**options)
To render this form into a view, move to views.py and create a view.
In view, one needs to just create an instance of the form class created above in forms.py.
Models.py
Views.py
admin.py
forms.py
Result analysis:
Student details are taken from the form and displayed in sorted order in the database.
Aim of the program: To develop an application to create a photo gallery using Bootstrap.
Description:
Bootstrap is the most popular HTML, CSS and JavaScript framework for developing a responsive
and mobile friendly website.
It includes HTML and CSS based design templates for typography, forms, buttons, tables,
navigation, modals, image carousels and many others.
For the bootstrap feature first, add CSS CDN to the webpage
1. Create a container with class container-fluid to cover the full width of the webpage.
2. Create a container with class jumbotron for Gallary heading and extra information
3. Now we will have a row container which will have column cells that will have a span of 12
for extra smaller devices, 6 for smaller devices, 4 for medium devices, and 3 for large or extra-large
devices. And each of these cells contains a figure element with an image and figure caption inside
it.
5. Inside row create cells with class col-sm-6, col-md-4, and col-lg-3.
6. Now each of these cells contains a figure element with an image inside having class img-
thumbnail and grayscale.
7. Add CSS filter property for grayscale class so that it has filter: grayscale(50%) when the
mouse is over the image.
Grid Classes:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<title>Photo gallery</title>
<h1 class="text-center">Photo gallery</h1>
<style>
figure {
margin: 15px 0;
}
figcaption {
text-align: center;
}
.grayscale {
filter: grayscale(0);
}
.grayscale:hover {
filter: grayscale(50%)
}
</style>
</head>
<body>
<div class="container-fluid">
<div class="row">
</figure>
</div>
</figure>
</div>
</figure>
</div>
<div class="col-sm-6 col-md-4 col-lg-3">
<figure>
<img src="https://images.unsplash.com/photo-1519681393784-
d120267933ba?ixid=MnwxMjA3fDB8MHxzZWFyY2h8N3x8bW91bnRhaW5zfGVufDB8fDB8fA
%3D%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=700&q=60" class="img-thumbnail
grayscale">
</figure>
</div>
<div class="col-sm-6 col-md-4 col-lg-3">
<figure>
<img src="https://images.unsplash.com/photo-1486870591958-
9b9d0d1dda99?ixid=MnwxMjA3fDB8MHxzZWFyY2h8OHx8bW91bnRhaW5zfGVufDB8fDB8f
A%3D%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=700&q=60" class="img-thumbnail
grayscale">
</figure>
</div>
</div>
</body>
</html>
Result analysis:
Aim of the program: To develop django application to find no of times user visited a web site.
Description:
Django Cookie:A cookie is a small piece of information which is stored in the client browser. It is
used to store user's data in a file permanently (or for the specified time).
Cookie has its expiry date and time and removes automatically when gets expire. Django provides
built-in methods to set and fetch cookie.
The set_cookie() method is used to set a cookie and get() method is used to get the cookie.
The request.COOKIES['key'] array can also be used to get cookie values.
Program code:
Admin.py:
Count.html
<html>
<body>
<h1>page count: {{count}}</h1>
</body>
</html>
Views.py
Result analysis:
The number of times a user visits a webpage is counted by cookies methods and displayed it on the
same webpage using templates in Django.
1.
Aim:Develop an application to create a student form(rollno, name,marks,feedback) and
save data in data base using django and display the student table in sorted order based
on marks in browser.
Description:
Django Forms
Forms are basically used for taking input from the user in some manner and using that
information for logical operations on databases. For example, Registering a user by
taking input as his name, email, password, etc.
Django maps the fields defined in Django forms into HTML input fields. 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
Syntax:
from django import forms
class FormName(forms.Form):
# each field would be mapped as an input field in HTML
field_name = forms.Field(**options)
To render this form into a view, move to views.py and create a view.
In view, one needs to just create an instance of the form class created above in
forms.py.
Program Code:
Models.py
from django.db import models
class Feedback(models.Model):
name=models.CharField(max_length=40)
rollno=models.IntegerField()
marks=models.FloatField()
feedback=models.CharField(max_length=30)
def str (self):
return self.name
forms.py
from django import forms
from FormsApp2.models import Feedback
class FeedbackForm(forms.ModelForm):
class Meta:
model=Feedback
fields=' all '
admin.py
from django.contrib import admin
from FormsApp2.models import Feedback
# Register your models here.
class FeedbackAdmin(admin.ModelAdmin):
list_display=['name','rollno','marks','feedback']
ordering=['-marks']
admin.site.register(Feedback,FeedbackAdmin)
Views.py
from django.shortcuts import render
from . import forms
from FormsApp2.models import Feedback
def feedbackdata(request):
form=forms.FeedbackForm()
if request.method=='POST':
form=forms.FeedbackForm(request.POST)
if form.is_valid():
form.save(commit=True)
return render(request,'FormsApp2/input.html',{'form':form})
def display(request):
list=Feedback.objects.all().order_by('-marks')
my_dict={'student_list':list}
return render(request,'FormsApp2/result.html',context=my_dict)
input.html
<html>
<title>Student Form</title>
<body>
<h1>Registration form</h1>
<form method="POST" action="">
{{form.as_p}}
{% csrf_token %}
<input type="submit" value="send_data"/>
</form>
</body>
</html>
result.html
<html>
<body>
<h1>Student Details</h1>
{% if student_list %}
<table border="2">
<thead>
<th>Roll no</th>
<th>Student Name</th>
<th>Marks</th>
<th>Feedback</th>
</thead>
{% for s in student_list %}
<tr>
<td>{{s.rollno}}</td>
<td>{{s.name}}</td>
<td>{{s.marks}}</td>
<td>{{s.feedback}}</td>
</tr>
{% endfor %}
</table>
{% else %}
<p>No Students</p>
{% endif %}
</body>
</html>
Urls.py
from django.contrib import admin
from django.urls import path
from FormsApp2 import views as v2
urlpatterns = [
path('admin/', admin.site.urls),
path('studentform',v2.feedbackdata), path('studentdata',v2.display)]
Output:
http://127.0.0.1:8000/studentform
http://127.0.0.1:8000/admin
http://127.0.0.1:8000/studentdata
Result Analysis:
Student details are taken from the form and displayed in sorted order in the database.
2.
Aim: Develop an application to create a photo gallery using Bootstrap
Description:
Bootstrap is the most popular HTML, CSS and JavaScript framework for developing a
responsive and mobile friendly website.
It includes HTML and CSS based design templates for typography, forms, buttons, tables,
navigation, modals, image carousels and many others.
Bootstrap Grid System is responsive and the columns are re-arranged automatically
according to the screen size.
Grid Classes:
There are four classes in Bootstrap Grid System:
• xs (for phones)
• sm (for tablets)
• md (for desktops)
• lg (for larger desktops)
Program Code:
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="bootstrap.css">
<style>
img{
height: 300px;
width: 350px;
}
</style>
</head>
<body>
<h1 align="center">Photo Gallery</h1>
<!-- Gallery -->
<div class="row">
<div class="col-lg-4 col-md-12 mb-4 mb-lg-0">
<img src="tulips.jpg" alt="no image"/>
<img src="rose.jpg" alt="no image"/>
<img src="roseorange.jpg" alt="no image"/>
<img src="flo3.jpg" alt="no image"/>
</div>
<div class="col-lg-4 col-md-12 mb-4 mb-lg-0">
<img src="sunflower.jpg" alt="no image"/>
<img src="flower4.jpg" alt="no image"/>
<img src="flower3.jpg" alt="no image"/>
<img src="rrr3.jpg" alt="no image"/>
</div>
</div></body>
<!-- Gallery -->
Output:
Result Analysis:
3.
Aim: Develop django application to find no of times user visited a web site
Description:
Django Cookie:A cookie is a small piece of information which is stored in the client
browser. It is used to store user's data in a file permanently (or for the specified time).
Cookie has its expiry date and time and removes automatically when gets expire. Django
provides built-in methods to set and fetch cookie.
The set_cookie() method is used to set a cookie and get() method is used to get the
cookie.
The request.COOKIES['key'] array can also be used to get cookie values.
Program Code:
Views.py
urls.py
from django.contrib import admin
from django.urls import path
from CookiesApp import views as v3
urlpatterns = [
path('admin/', admin.site.urls),path('formdata/',v1.studentData),
path('studentform',v2.feedbackdata),path('count',v3.count_requests)
]
count.html
<!DOCTYPE html>
<body>
<h1>Page count : {{count}}</h1>
</body>
Output:
Result Analysis:
The no.of times a user visits a webpage is counted by cookies methods and displayed it
on the same webpage using templates in Django.