繼瓶教程,運行Windows 7,Python的2.7.3,virtualenv中,和我被困在第3步:創建數據庫http://flask.pocoo.org/docs/tutorial/dbinit/#tutorial-dbinit停留在瓶教程步驟3
Such a schema can be created by piping the schema.sql file into the sqlite3 command as follows:
sqlite3 /tmp/flaskr.db < schema.sql
如何運行此命令,因爲CMD < venv>回報:
"sqlite3" is not recognized as internal or external command, operable program or batch file.
此步驟是否必要?
文件夾項目,2個文件schema.sql和flaskr.py。
schema.sql文件
drop table if exists entries;
create table entries (
id integer primary key autoincrement,
title string not null,
text string not null
);
flaskr.py
# all the imports
import sqlite3
from flask import Flask, request, session, g, redirect, url_for, \
abort, render_template, flash
from contextlib import closing
# configuration
DATABASE = '/tmp/flaskr.db'
DEBUG = True
SECRET_KEY = 'development key'
USERNAME = 'admin'
PASSWORD = 'default'
# create our little application :)
app = Flask(__name__)
app.config.from_object(__name__)
app.config.from_envvar('FLASKR_SETTINGS', silent=True)
def connect_db():
return sqlite3.connect(app.config['DATABASE'])
def init_db():
with closing(connect_db()) as db:
with app.open_resource('schema.sql') as f:
db.cursor().executescript(f.read())
db.commit()
if __name__ == '__main__':
app.run()
<venv> python
>>> from flaskr import init_db
>>> init_db()
Trackeback <most recent call last>:
File "<stdin>", line 1, in <module>
File "flaskr.py", line 24, in init_db
with closing (connect_db()) as db:
File "flaskr.py", line 21, in connect_db
return sqlite3.connect(app.config['DATABASE'])
sqlite3.OperationalError: unable to open database.
命令行工具在Windows上稱爲'sqlite3.exe'。 –
'sqlite3.OperationalError'會由SQLite無法*寫*已配置的數據庫文件(如果尚不存在,則會創建一個)。 –
已下載sqlite3.exe,sqlitie> sqlite3 /tmp/flaskr.db任何幫助? –