from flask import Flask, jsonify, render_template
app = Flask(__name__, template_folder='templates')
@app.route('/json')
def index1():
"""
返回json数据
:return:
"""
return jsonify({'name': 'gkl'})
@app.route('/string')
def index2():
"""
返回字符串
:return:
"""
return '返回字符串'
@app.route('/template')
def template():
"""
返回模板文件
:return:
"""
return render_template('index.html')
if __name__ == '__main__':
app.run(debug=True)
1. 模板文件
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1 style="color: pink">模板文件</h1>
</body>
</html>
2. 访问
![在这里插入图片描述](https://img-blog.csdnimg.cn/20191201190804753.png)