2017-02-20 99 views
1

我已閱讀此問題(https://github.com/pallets/flask/issues/1902)和此問題(https://github.com/pallets/flask/issues/1902)以及與Github上的示例項目逐行比較。我找不到解決方案。卡住燒瓶教程步驟5「initdb」不識別

當我運行

export FLASK_APP=flaskr 
flask initdb 

我得到這個錯誤:

Usage: flask [OPTIONS] COMMAND [ARGS]... 

Error: No such command "initdb". 

在initdb:

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

@app.cli.command('init_db') 
def initdb_command(): 
    init_db() 
    print("Initialized the database.") 

任何想法?

事情我已經嘗試:

export FLASK_APP=flaskr 

確信與更新pip install https://github.com/mitsuhiko/flask/tarball/master

+0

你的'initdb'自定義命令代碼塊是什麼樣的? – glibdud

+0

@glibdud請參閱編輯 – thaneofcawdor

+0

請在問題中發帖,但我正在尋找'@ app.cli.command('initdb')'之前的函數。 – glibdud

回答

1

你叫你的自定義命令init_db

@app.cli.command('init_db') 

因此運行它,你會需要使用:

flask init_db 
+1

呃。我討厭在發佈之前無法捕捉的愚蠢錯字錯誤。謝謝。很抱歉打擾。 – thaneofcawdor