3.3.3-Flask - 模板渲染【多选一:Flask系列】
第1关:模板渲染 - 变量输出
1.py
from flask import Flask, render_template, request
app = Flask(__name__)
map = {
"1": {
"id": "1",
"sex": "女",
"age": "18",
"introduce": "不忘初心,方得始终",
"interest": "偶尔发发神经,听听歌,看看新闻。"
},
"2": {
"id": "2",
"sex": "男",
"age": "18",
"introduce": "不忘初心,方得始终",
"interest": "偶尔发发神经,听听歌,吹吹口琴。"
}
}
#####Begin#####
@app.route('/index',methods=['GET','POST'])
def index():
id = request.args.get('name')
return render_template("1.html", id=map[id]['id'], sex=map[id]['sex'], age=map[id]['age'], introduce=map[id]['introduce'],interest=map[id]['interest'])
#####End#####
if __name__ == '__main__':
app.run(host="0.0.0.0", port=8080)
1.html
<!DOCTYPE HTML>
<html lang="zh-Hans">
<head>
<meta charset="utf-8">
<link rel='stylesheet' href={
{url_for('static',filename='css/css.css')}} type='text/css'/>
<link rel='stylesheet' href={
{url_for('static',filename='css/font-awesome.min.css')}} type='text/css'/>
<link rel='stylesheet' href={
{url_for('static',filename='css/style.css')}} type='text/css'/>
<title>I am I - 个人主页</title>
<script src={
{url_for('static',filename='js/jquery.min.js')}}></script>
<script src={
{url_for('static',filename='js/skel.min.js')}}></script>
<script src={
{url_for('static',filename='js/util.js')}}></script>
</head>
<body>
<div id="wrapper">
<article id="about-me" class