Flask笔记(一)
其他
2020-07-26 12:41:20
阅读次数: 0
pipenv 创建虚拟环境
- 全局安装 pipenv,通过命令 pip install pipenv
- 打开终端,进入目标文件夹,输入命令 pipenv install,绑定项目
- 输入命令 pipenv shell,进入虚拟环境
- 输入命令 pipenv install flask,安装 flask
- 最后 exit, 退出虚拟环境
配置文件
代码(附注释
- demo.py:
from flask import Flask, make_response
app = Flask(__name__)
app.config.from_object('config')
@app.route('/hello/')
def hello():
return 'Hello, SixGod'
@app.route('/hello2/')
def hello2():
return '<html><body><p>Hi, Liushen</p></body></html>'
@app.route('/hello3/')
def hello3():
headers = {
'content-type': 'text/plain'
}
response = make_response('<html></html>', 404)
response.headers = headers
return response
@app.route('/hello4/')
def hello4():
headers = {
'content-type': 'application/json',
'location': 'https://blog.csdn.net/hongwangdb'
}
return '<html></html>', 301, headers
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=app.config['DEBUG'], port=85)
转载自blog.csdn.net/hongwangdb/article/details/104442373