Skip to main content
 首页 » 编程设计

python之导入 init_db( flask 教程)

2025年05月04日10davidwang456

我已经看完了flask的教程(http://flask.pocoo.org/docs/tutorial/introduction/)

现在我遇到错误,你能帮帮我吗? :)

在 github 上,它在自述文件中这样说......(https://github.com/mitsuhiko/flask/tree/master/examples/flaskr/)

fire up a python shell and run this: 
 
from flaskr import init_db; init_db() 

所以我打开我的 python shell 并输入它......唯一的问题是我收到一个导入错误,说它找不到 flaskr......

如果我尝试在本地运行 flaskr.py 文件,我就会得到这个

sqlite3.OperationalError OperationalError: unable to open database file 

总的来说,我对这个和 python 真的很陌生,所以任何帮助都会很棒,谢谢。

请您参考如下方法:

您是否创建了数据库文件?

在 flaskr.py 中的第 19 行, 给出了数据库的路径。

DATABASE = '/tmp/flaskr.db' 

该文件需要存在。