利用flask框架制作一个学生信息简洁页面,要求页面简介大方
后端
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/student/<name>')
def student(name):
# 定义一个字典,存储学生的姓名、年龄、专业信息
student_info = {
'name': name,
'age': 20,
'major': 'Computer Science'
}
return render_template('student.html', student=student_info)
if __name__ == '__main__':
app.run(debug=True)
前端:
<!DOCTYPE html>
<html>
<head>
<title>Student Information</title>
</head>
<body>
<h1>{{ student.name }}'s Information</h1>
<p>Age: {{ student.age }}</p>
<p>Major: {{ student.major }}</p>
</body>
</html>