flask:1启动flask服务器(hello world)

1.用pipenv创建项目环境。

2.在项目目录中新建一个mytest.py文件,输入以下代码:


from flask import Flask

app=Flask(__name__)

@app.route('/')
def index():
    return '<h1>Hello World</h1>'

@app.route('/hello/<name>')
def name(name):
    return '<h1>Hello %s</h1>1' % name

app.run()

2.运行文件

python mytest.py

 输出

 * Serving Flask app "mytest" (lazy loading)
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

3.访问网页

http://127.0.0.1:5000/hello/ljz

4.开启flask调试模式

app.run(debug=True)

猜你喜欢

转载自blog.csdn.net/qq_18598403/article/details/85109730