Tuesday 7 June 2011

A Simple Flask-Script Example

Here is a simple flask-script example that you can use to start your application in development mode, or test modes.

I know that you can do that without flask-script, but the point of this script is that you can do so much more from this starting point. Notice for example that I'm trying to load flask-lesscss and execute it (which won't work, but won't fail if you don't have lesscss installed.)

To get the application (in the 'application' module) running you just need to do one of the following:

python manager.py dev
python manager.py test
python manager.py zen

I show how to add shell access in the second article in this series. Meanwhile why not let us see what you have in your manager script?

from flaskext.script import Manager, Server
from flaskext.zen import Test, ZenTest
import application


app = application.create_app()

manager = Manager(app)

class DevServer(Server):
    
    def handle(self, app, host, port, use_debugger, use_reloader):
        try:
            from flaskext.lesscss import lesscss
            lesscss(app)
        except: pass

        app.run(host=host,
            port=port,
            debug=use_debugger,
            use_debugger=use_debugger,
            use_reloader=use_reloader,
            **self.server_options)
            
            
if __name__ == "__main__":
    manager.add_command("dev", DevServer())
    manager.add_command('test', Test())
    manager.add_command('zen', ZenTest())
    manager.run()
    

No comments:

Post a Comment