flask启动过程+实现网页跳转

目录

 

1. 激活虚拟环境

2.设置变量

3. html文件

4. myflask.py文件内容

5. 执行flask

6.第二种执行flask的方法


1. 激活虚拟环境

cd到工程目录

E:\workspace\ffmpeg\bin>cd E:\workspace\stock\hdf5test

E:\workspace\stock\hdf5test>
E:\workspace\stock\hdf5test>venv\Scripts\activate

2.设置变量

(venv) E:\workspace\stock\hdf5test>set FLASK_APP=myflask.py

myflask.py在工程目录E:\workspace\stock\hdf5test\下,与venv虚拟环境文件夹同层目录。

3. html文件

工程目录E:\workspace\stock\hdf5test\下新建目录static,放入index.html

<html>

<body>

<p>
<a href="/config">config</a>
</p>

<p>
<a href="/query">query</a>
</p>

</body>
</html>

4. myflask.py文件内容

# coding=gbk

from flask import Flask
app = Flask(__name__)

#1.修改配置
@app.route('/config')
def config():
    return '配置你的配置'

#2.查询信息
@app.route('/query')
def query():
    return '你要的结果'

@app.route('/')
def index():
    print('index')
    return app.send_static_file('index.html')

if __name__ == "__main__":
    print('this is main!')
    #use_reloader=False  防止执行两遍
    app.run(host='0.0.0.0', port=5000, debug=True, use_reloader=False)

5. 执行flask

(venv) E:\workspace\stock\hdf5test>flask run -h 0.0.0.0 -p 5000

为了让其他PC可以访问,加上-h -p

6.第二种执行flask的方法

(venv) E:\workspace\stock\hdf5test>python myflask.py
this is main!
 * Serving Flask app "myflask" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployme
nt.
   Use a production WSGI server instead.
 * Debug mode: on
 * Restarting with stat
this is main!
 * Debugger is active!
 * Debugger PIN: 254-244-829
 * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)

用python myflask.py来启动flask,会进入main函数:

if __name__ == "__main__":
    print('this is main!')
    #use_reloader=False  防止执行两遍
    app.run(host='0.0.0.0', port=5000, debug=True, use_reloader=False)

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值