新人按着flask教程一步一步的走,报错..求指导...

教程地址:http://docs.jinkan.org/docs/flask/tutorial/dbinit.html#tutorial-dbinit
#alltheimports
importsqlite3
fromflaskimportFlask,request,session,g,redirect,url_for,abort,render_template,flash
#configuration
DATABASE='/tmp/flaskr.db'
DEBUG=True
SECRET_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')asf:
db.cursor().executescript(f.read())
db.commit()
if__name__=='__main__':
app.run()
在Pythonshell里创建数据库这一步报如下错误:
>>>init_db()
Traceback(mostrecentcalllast):
File"",line1,in
File"flaskr.py",line18,ininit_db
withclosing(connect_db())asdb:
NameError:globalname'closing'isnotdefined
ibeautiful
浏览 423回答 2
2回答

SMILET

fromfutureimportwith_statementfromcontextlibimportclosing这两个导入你没做吧?
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript