V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
tylr
V2EX  ›  Flask

官方教程p29#unable to open database file的问题

  •  
  •   tylr · Apr 22, 2012 · 5893 views
    This topic created in 5130 days ago, the information mentioned may be changed or developed.
    我正在照着官方的doc写flaskr这个范例(windows系统下)

    进展到p29的‘create database in python shell’那步时出现如下的报错

    C:\Documents and Settings\t\Desktop\flask\flaskr>python
    Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win
    32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from flaskr import init_db
    >>> init_db()
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "flaskr.py", line 37, in init_db
    with closing(connect_db()) as db:
    File "flaskr.py", line 32, in connect_db
    return sqlite3.connect(app.config['DATABASE'])
    sqlite3.OperationalError: unable to open database file


    配置中的数据库文件是这样的:
    DATABASE = '/tmp/flaskr.db'

    貌似/tmp/是linux下的路径吧,windows系统下面没有该路径以及flask.db文件导致了sqlite3无法打开数据库文件,我试探性的将其改为了:
    DATABASE = 'flaskr.db' #希望能在当前目录下寻找该数据库文件
    并且在flaskr文件夹内右键新建了个flaskr.db的文件

    但是还是报同样的错误,那该如何解决呢?
    1 replies    1970-01-01 08:00:00 +08:00
    Hualin
        1
    Hualin  
       Nov 29, 2012
    刚试完,是这样的。
    改成:
    DATABASE = 'flaskr.db'
    并在 flaskr 的文件下建一个空文件 flaskr.db
    然后暂时就可以跑起来了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2493 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 00:55 · PVG 08:55 · LAX 17:55 · JFK 20:55
    ♥ Do have faith in what you're doing.