请问以下Flask数据库配置哪里出错了呢?我是根据教程一步一步来做的:教程:http://dormousehole.readthedocs.org/en/latest/tutorial/dbinit.html#tutorial-dbinit#------code------#alltheimportsimportsqlite3fromflaskimportFlask,request,session,g,redirect,url_for,abort,render_template,flashfromcontextlibimportclosing#configurationDATABASE='/tmp/flaskr.db'DEBUG=TrueSECRET_KEY='developmentkey'USERNAME='admin'PASSWORD='default'#createourlittleapplication:)app=Flask(__name__)app.config.from_envvar('FLASKR_SETTINGS',silent=True)defconnect_db():returnsqlite3.connect(app.config['DATABASE'])definit_db():withclosing(connect_db())asdb:withapp.open_resource('schema.sql',mode='r')asf:db.cursor().executescript(f.read())db.commit()#------RuninginPythonIDEL------>>>fromflaskrimportinit_db>>>init_db()Traceback(mostrecentcalllast):File"",line1,inFile"flaskr.py",line22,ininit_dbwithclosing(connect_db())asdb:File"flaskr.py",line19,inconnect_dbreturnsqlite3.connect(app.config['DATABASE'])KeyError:'DATABASE'
添加回答
举报
0/150
提交
取消