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 them; I get the following error:
@app.cli.command('initdb')
AttributeError: 'Flask' object has no attribute 'cli'
I used pip install flask
to install Flask. Why can't I run the repo code?
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With