Skip to content Skip to sidebar Skip to footer

Can't Run Example Code Referenced In Flask Docs

I am reading the Flask docs and want to use the examples they reference that are in the git repo. However, the tutorials don't match the code in the repository, and I can't run th

Solution 1:

You are reading the development docs, but using the latest stable release (0.10.1). The current builds include many changes, including a cli. To try out the latest code, use:

pip install https://github.com/mitsuhiko/flask/tarball/master

To get something similar in the latest stable release, you either need to write your own commands or use a third-party extension such as Flask-Script. A new extension, Flask-CLI, backports the new Click interface from master to the stable version.


Solution 2:

Here is how I made it work:

change the function init_db()

def init_db():
    with app.app_context():
        db = get_db()
        with app.open_resource('schema.sql', mode='r') as f:
            db.cursor().executescript(f.read())
        db.commit()

And add this,

if __name__ == '__main__':
    init_db()
    app.run()

To run,

python flaskr.py


Solution 3:

Or you could manipulate the the example python script like this, take this example for instance

  1. install click pip install click
  2. modify minitwit.python, importing FlaskCli from flask_cli module
  3. initialise it by adding FlaskCLI(app) under app.config.from_envvar('MINITWIT_SETTINGS', silent=True)

Post a Comment for "Can't Run Example Code Referenced In Flask Docs"