1cmd安装
pip install flask
2编写
from flask import Flask
#Flask的基本使用
app = Flask(__name__)
# 使用@app.route装饰器来定义路由
@app.route('/')
def hello_world():
return 'Hello world!'
if __name__ == '__main__':
app.run()
可能遇到的问题,用了render_template后jinja2.exceptions.TemplateNotFound: index.html 报错
#框架模板,使用页面渲染
from flask import Flask,render_template
app = Flask(__name__)
@app.route('/')
def index():
# jinja2.exceptions.TemplateNotFound: index.html 报错
# 解决 同级目录添加 templates 文件夹 并将 index和 __init__ 文件放里面
return render_template('index.html', title = 'html页面', name = 'Flask')
if __name__ == '__main__':
app.run()