zoukankan      html  css  js  c++  java
  • 【FLASK】Flask-Script

    Flask Script扩展提供向Flask插入外部脚本的功能

    Manager

    Manager可以看作是一个监视命令行的脚本,该脚本同时也可以添加命令,有三种方法添加命令:

    1.创建Command子类,子类必须定义一个run方法

    from flask_script import Manager
    from flask_script import Command
    from debug import app
    
    manager = Manager(app)
    
    class Hello(Command):
        'hello world'
        def run(self):
            print('hello world')
    
    manager.add_command('hello',Hello())
    if __name__ == "__main__":
        manager.run()
    
    结果:
    python manager.py hello
    > hello world
    

    2.使用Command实例的@command修饰符

    #-*-coding:utf8-*-  
    from flask_script import Manager  
    from debug import app  
      
    manager = Manager(app)  
     
    @manager.command  
    def hello():  
        'hello world'  
        print 'hello world'  
      
    if __name__ == '__main__':  
        manager.run()  
    
    结果:
    python manager.py hello
    > hello world
    

    3.使用Command实例的@option修饰符

    #-*-coding:utf8-*-  
    from flask_script import Manager  
    from debug import app  
      
    manager = Manager(app)  
     
    @manager.option('-n', '--name', dest='name', help='Your name', default='world')  
    @manager.option('-u', '--url', dest='url', default='www.csdn.com')  
    def hello(name, url):  
        'hello world or hello <setting name>'  
        print 'hello', name  
        print url  
      
    if __name__ == '__main__':  
        manager.run()  
    
    结果:
    python manager.py hello
    >hello world
    >www.csdn.com
    
    python manager.py hello -n sissiy -u www.sissiy.com
    > hello sissiy
    >www.sissiy.com
    

    参考文档

    不怕世界大,就怕格局小
  • 相关阅读:
    Vue中v-for不绑定key会怎样
    关于Vuex可直接修改state问题
    不要完全相信Chrome控制台打印的信息
    Vue挂载元素的替换
    (转)openURL的使用方法
    iOS:将NSDate转换为当前时区时间
    OC中使用 static 、 extern、 const使用
    iOS: 正则表达式
    iOS:原生二维码扫描
    iOS:ABPeoplePickerNavigationController系统通讯录使用
  • 原文地址:https://www.cnblogs.com/wangjian1226/p/10511674.html
Copyright © 2011-2022 走看看