[ 已解决 ] 有学 python flask 的朋友吗? 遇到一个坑... 实在没地问了

教程地址:http://docs.jinkan.org/docs/flask/tutorial/dbinit.html#tutorial-dbinit
按着教程一步一步的走, 报错…
我的代码如下:

2 from contextlib import closing
3 import sqlite3
4 from flask import Flask, request, session, g, redirect, url_for,
5 abort, render_template, flash
6 # configuration
7 DATABASE = ‘/tmp/flaskr.db’
8 DEBUG = True
9 SECRET_KEY = ‘development key’
10 USERNAME = ‘admin’
11 PASSWORD = ‘default’
12 # create our little application :slight_smile:
13 app = Flask(name)
14 app.config.from_envvar(‘FLASKR_SETTINGS’, silent=True)
15 def connect_db():
16 return sqlite3.connect(app.config’DATABASE’])
17 def init_db():
18 with closing(connect_db()) as db:
19 with app.open_resource(‘schema.sql’) as f:
20 db.cursor().executescript(f.read())
21 db.commit()
22 if name == ‘main’:
23 app.run()

报错:

from flaskr import init_db
init_db()
Traceback (most recent call last):
File “”, line 1, in
File “flaskr.py”, line 18, in init_db
with closing(connect_db()) as db:
File “flaskr.py”, line 16, in connect_db
return sqlite3.connect(app.config’DATABASE’])
KeyError: ‘DATABASE’

应该是你的这个文件不存在吧,请确保该文件存在且当前用户具有读写权限。
最简单的做法

touch /tmp/flaskr.db

然后再执行你的代码试试。
@knowaeap

谢谢… 解决了…