当前位置 : 主页 > 编程语言 > python >

python-flask-script定制manage命令

来源:互联网 收集:自由互联 发布时间:2022-06-15
安装: pip3 install flask-script #!/usr/bin/env python # -*- coding:utf-8 -*- from flask_script import Manager, Server from flask import Flask app = Flask(__name__) manager = Manager(app) @manager.command def custom(arg): """ 自定义命令
安装: pip3 install flask-script


#!/usr/bin/env python
# -*- coding:utf-8 -*-

from flask_script import Manager, Server
from flask import Flask

app = Flask(__name__)
manager = Manager(app)


@manager.command
def custom(arg):
"""
自定义命令
python manage.py custom 123
:param arg:
:return:
"""
print(arg)


@manager.option('-n', '--name', dest='name')
@manager.option('-u', '--url', dest='url')
def cmd(name, url):
"""
自定义命令
执行: python manage.py cmd -n wupeiqi -u http://www.oldboyedu.com
:param name:
:param url:
:return:
"""
print(name, url)


@manager.command
def import_news(path):
"""
批量导入
:param name:
:param url:
:return:
"""
import xlrd
from xlrd.book import Book
from xlrd.sheet import Sheet
from xlrd.sheet import Cell
workbook = xlrd.open_workbook(path)
sheet_names = workbook.sheet_names()
# sheet = workbook.sheet_by_name('工作表1')
sheet = workbook.sheet_by_index(0)

# 循环Excel文件的所有行
for row in sheet.get_rows():
# print(row)
# 循环一行的所有列
for col in row:
# 获取一个单元格中的值
print(col.value,end=';')
print('')

# 自定义命令
manager.add_command("runserver", Server())

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


上一篇:python 利用selectors实现异步I/O
下一篇:没有了
网友评论