2
ここは私のフラスコの一部です127.0.0.1:5000で実行しようとしましたが、エラー。OperationalError:このようなテーブルはありません: "init_db()"はすでにフルスペルピに挿入されています
app = Flask(__name__)
app.config.from_object(__name__)
app.config.from_envvar('FLASKR_SETTINGS', silent=True)
def init_db():
"""Creates the database."""
with app.app_context():
db = get_db()
with app.open_resource('/var/www/html/flaskr/schema.sql', mode='r') as f:
db.cursor().executescript(f.read())
db.commit()
def get_db():
"""
Opens a new database connection if there is none yet for the
current application context.
"""
top = _app_ctx_stack.top
if not hasattr(top, 'sqlite_db'):
sqlite_db = sqlite3.connect(app.config['DATABASE'])
sqlite_db.row_factory = sqlite3.Row
top.sqlite_db = sqlite_db
return top.sqlite_db
@app.route('/')
def show_entries():
db = get_db()
with open('/var/www/html/flaskr/hardwarelist.txt') as fl:
for eachline in fl:
(model,sn,user,status)=eachline.strip().split(',')
db.execute('insert into entries (model,sn,user,status) values (?, ?, ?, ?)',(model,sn,user,status))
fl.close()
cur = db.execute('select model,sn,status,user from entries order by id desc')
entries = cur.fetchall()
return render_template('show_entries.html', entries=entries)
if __name__ == '__main__':
init_db()
app.run()
私はうまく実行されなかったエラーが私の「INIT_DB」機能から生じたと思ったので、私はできません: は、その後、私はここで
File "/var/www/html/flaskr/flaskr.py", line 66, in show_entries (model,sn,user,status))
OperationalError: no such table: entries "
は私のコードであり、telledのerror_logをチェックエントリのテーブルを取得します。 init_dbに関するエラー報告はありませんでしたが、この質問を解決するにはどうすればよいですか?&はそれを修正しましたか?
更新: 私のschema.sqlがあります:
drop table if exists entries;
create table entries (
id integer primary key autoincrement,
model text not null,
sn text not null,
status text not null,
user text not null
);
データベースの設定方法を示すコードを掲載することはできますか? – coralvanda
@coralv確かに、私はschema.sqlを入れましたが、あなたが意味するものかどうかは分かりません。 –
ありがとうございます。残念ながら、私はあなたの問題を引き起こしているのか分かりません。答えを出すことができる人の注意を引くことを望んでいる。 – coralvanda