教程地址:http://docs.jinkan.org/docs/flask/tutorial/dbinit.html#tutorial-dbinit#alltheimportsimportsqlite3fromflaskimportFlask,request,session,g,redirect,url_for,abort,render_template,flash#configurationDATABASE='/tmp/flaskr.db'DEBUG=TrueSECRET_KEY='developmentkey'USERNAME='admin'PASSWORD='default'#createourlittleapplicationapp=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')asf:db.cursor().executescript(f.read())db.commit()if__name__=='__main__':app.run()在Pythonshell里创建数据库这一步报如下错误:>>>init_db()Traceback(mostrecentcalllast):File"",line1,inFile"flaskr.py",line18,ininit_dbwithclosing(connect_db())asdb:NameError:globalname'closing'isnotdefined
添加回答
举报
0/150
提交
取消