1.建文件夹,本次按flask默认要求建立templates文件夹-----》index.html
Apps folder
/app.py
templates
|-/index.html
2.index.html文件代码如下
<html>
<body>
{% if name %}
<h2>Hello {{ name }}.</h2>
{% else %}
<h2>Hello.</h2>
{% endif %}
</body>
</html>
3.编写逻辑代码
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/hello')
def hello():
return render_template('index.html', name="Jim")
if __name__ == '__main__':
app.run(debug = True)
4.输入127.0.0.1:5000/hello/jim
页面就可以按要求显示内容了。