0% found this document useful (0 votes)
9 views6 pages

Flask Student Results Application

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views6 pages

Flask Student Results Application

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Course:pfsd

Course_id:22DC101A

Section:S-33

Id:2200090067

Name: p aakash
Pre-Lab:

a) Hello World: This is a simple program that displays "Hello, World!" in the browser.

from flask import Flask

app = Flask(__name__)

@[Link]('/')

def hello_world():

return 'Hello, World!'

if __name__ == '__main__':

[Link](debug=True)

output:

* Running on [Link]

In-Lab:

a)Design and develop a Flask application to demonstrate Student results. Using Home. Courses, Rankers
Gallery.

from flask import Flask, render_template

app = Flask(__name__)

students = [

{"name": "Alice", "course": "Math", "marks": 90},

{"name": "Bob", "course": "Science", "marks": 85},

{"name": "Charlie", "course": "History", "marks": 78},

]
@[Link]('/')

def home():

return render_template('[Link]', students=students)

@[Link]('/courses')

def courses():

return render_template('[Link]', students=students)

@[Link]('/rankers-gallery')

def rankers_gallery():

return render_template('rankers_gallery.html', students=students)

if __name__ == '__main__':

[Link](debug=True)

html templates:

[Link]

<!DOCTYPE html>
<html>
<head>
<title>Home</title>
</head>
<body>
<h1>Welcome to the Home Page</h1>
<h2>Student Results</h2>
<table>
<thead>
<tr>
<th>Name</th>
<th>Course</th>
<th>Marks</th>
</tr>
</thead>
<tbody>
{% for student in students %}
<tr>
<td>{{ [Link] }}</td>
<td>{{ [Link] }}</td>
<td>{{ [Link] }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</body>
</html>

[Link]

<!DOCTYPE html>
<html>
<head>
<title>Courses</title>
</head>
<body>
<h1>Courses Offered</h1>
<ul>
<li>Math</li>
<li>Science</li>
<li>History</li>
<!-- Add more courses as needed -->
</ul>
</body>
</html>

[Link]

<!DOCTYPE html>
<html>
<head>
<title>Rankers Gallery</title>
<style>
.rankers-table {
border-collapse: collapse;
width: 100%;
}

.rankers-table th, .rankers-table td {


border: 1px solid #ddd;
padding: 8px;
text-align: left;
}

.rankers-table th {
background-color: #f2f2f2;
}

.rankers-table tr:nth-child(even) {
background-color: #f2f2f2;
}
</style>
</head>
<body>
<h1>Rankers Gallery</h1>
<table class="rankers-table">
<thead>
<tr>
<th>Name</th>
<th>Course</th>
<th>Marks</th>
</tr>
</thead>
<tbody>
{% for student in students %}
<tr>
<td>{{ [Link] }}</td>
<td>{{ [Link] }}</td>
<td>{{ [Link] }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</body>
</html>

Output:

* Running on [Link]

* Running on [Link]

* Running on [Link]
Post-Lab:

a) How can I handle different HTTP methods (GET, POST, etc.) in Flask? In Flask, you can handle different
HTTP methods by specifying them in the route decorator using the methods parameters.

from flask import Flask, request

app = Flask(__name__)

@[Link]('/example', methods=['GET', 'POST'])


def example():
if [Link] == 'GET':
# Handle GET requests here
return 'This is a GET request.'

if [Link] == 'POST':
# Handle POST requests here
data = [Link]('data') # Access form data
return f'This is a POST request with data: {data}'

if __name__ == '__main__':
[Link](debug=True)

output:

* Running on [Link]

You might also like