python flask demo

2024-10-09 08:04:33 浏览数 (1)

1.安装pycharm  flask

2.查看帮助

代码语言:javascript复制
#import requests;
from flask import Flask

#help(requests)
help(Flask)

3.demo 

代码语言:javascript复制
from flask import Flask

app = Flask(__name__)

@app.route("/index")
def index():
    return "<h1 style='color:red'>Hello World</h1>"

@app.route('/test')
def hello_world():
    return 'hello world test'

if __name__ == "__main__":
    #app.run()  #默认端口 5000
    app.run(host='127.0.0.1',port=5001) # 指定端口,ip

  4.访问

http://127.0.0.1:5001/test

http://127.0.0.1:5001/index

0 人点赞