1.安装插件:

pip install flask_script

2.代码:

#encoding:utf-8
from flask_sqlalchemy import SQLAlchemy
from flask_script import Manager,Shell
from flask import Flask
 
app = Flask(__name__)
manager = Manager(app)
db = SQLAlchemy(app)
db = SQLAlchemy(use_native_unicode='utf8')

test_data={'user':'lanyue','pass':'lanyue0406'}

def make_shell_context():
    return dict(app=app,db=db,data=test_data)

manager.add_command("shell",Shell(make_context=make_shell_context))
    
@app.route('/')
def index():
       return '欢迎登录'

if __name__=='__main__':
       manager.run()

 

3.执行shell:

python index.py shell

4.效果图:


flask 入门 之 Python Shell (一)

 

相关文章:

  • 2021-10-10
  • 2021-11-13
  • 2022-12-23
  • 2021-04-13
  • 2021-08-09
  • 2021-08-13
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-04-25
  • 2021-10-05
  • 2021-12-29
  • 2021-06-23
  • 2021-08-28
  • 2022-01-19
  • 2022-12-23
相关资源
相似解决方案