1. 多app应用(了解)
### 多个app实例(启用)
from werkzeug.wsgi import DispatcherMiddleware
from werkzeug.serving import run_simple
from flask import Flask, current_app
app1 = Flask('app01')
app2 = Flask('app02')
@app1.route('/index')
def index():
return "app01"
@app2.route('/index2')
def index2():
return "app2"
# http://www.oldboyedu.com/index
# http://www.oldboyedu.com/sec/index2
dm = DispatcherMiddleware(app1, {
'/sec': app2,
})
if __name__ == "__main__":
run_simple('localhost', 5000, dm)
# 请求来了,会执行dm()--->__call__
2. flask-script(制定命令)
1 模拟出类似django的启动方式:python manage.py runserver
2 pip install flask-script
3 把excel的数据导入数据库,定制个命令,去执行(openpyxl)
python manage.py insertdb -f xxx.excl -t aa
4 使用
-方式一:python manage.py runserver
from flask import Flask
from flask_script import Manager
app = Flask(__name__)
manager=Manager(app)
if __name__ == '__main__':
manager.run()
-方式二:自定制命令
@manager.command
def custom(arg):
print(arg)
@manager.option('-n', '--name', dest='name')
@manager.option('-u', '--url', dest='url')
def cmd(name, url):
print(name, url)
5 创建超级用户
6 现在有一万条excel用户,批量导入到数据库中
-navicate直接支持
-脚本
-flask-script