<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Students Record</title>
</head>
<body>
<h2>Students Record</h2>
<ul>
<li><a href="detail?studentid=1">Ben</a></li>
<li><a href="detail?studentid=2">Abu</a></li>
<li><a href="detail?studentid=3">Abiodun</a></li>
</ul>
</body>
</html>
from flask import Flask, render_template, request
# this block will render the student list page
@app.route('/students')
def students():
return render_template('items.html')
# display detail using the collected value
@app.route('/detail', methods=['GET', 'POST'])
def method():
if request.method == 'GET':
#the request get that collects the data
student_id = request.args.get('studentid')
if student_id=="1":
student_name="Ben"
if student_id=="2":
student_name="Abu"
if student_id=="3":
student_name="Abiodun"
return render_template('detail.html', stuid=student_id, stuname=student_name)
if __name__ == '__main__':
app.run(debug=True)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Students Record</title>
</head>
<body>
<h2>Students Record</h2>
{% if stuid %}
<p>Student id: {{ stuid }}</p>
<p>Student name: {{ stuname }}</p>
{% else %}
<p>Record not found!</p>
{% endif %}
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Students Record</title>
</head>
<body>
<h2>Students Record</h2>
<form method="GET" action ="detail">
Select Student:<br/>
<select name="studentid">
<option value="1">Ben</option>
<option value="2">Abu</option>
<option value="3">Abiodun</option>
</select>
<input type="submit" value="Search"/>
</form>
</body>
</html>
<form method="GET" action ="detail">
@app.route('/studentsform')
def studentsform():
return render_template('items_form.html')
from flask import Flask, render_template, request
app = Flask(__name__)
# get request
@app.route('/students')
def students():
return render_template('items.html')
@app.route('/studentsform')
def studentsform():
return render_template('items_form.html')
@app.route('/detail', methods=['GET', 'POST'])
def method():
if request.method == 'GET':
student_id = request.args.get('studentid')
if student_id=="1":
student_name="Ben"
if student_id=="2":
student_name="Abu"
if student_id=="3":
student_name="Abiodun"
return render_template('detail.html', stuid=student_id, stuname=student_name)
if __name__ == '__main__':
app.run(debug=True
No Comment yet!