最近在學習flask,使用sqlalchemy的時候遇到了問題,我用的是win10系統,設定檔如下:
class DevelopmentConfig(Config):
DEBUG = True
DATABASE_URI = 'sqlite:////F:/code/python/fishkeeping/fishkeeping/fish.db'
USERNAME = 'admin'
PASSWORD = 'a00123456'
SECRET_KEY = '11f0394a7e0c-4585-af6b-5b4efcf6fd8f'
之後發生了打不開資料庫的異常,發現路徑被程式修改為了
'C:\F:\code\python\fishkeeping\fishkeeping\fish.db'
試了好幾次,發現不管sqlite:////
後面接的是什麼,都會在前面加一個C:\\
,非常詭異,求解決。
淡淡烟草味2017-05-27 17:41:23
官方文件有交待engine = create_engine('sqlite:///C:pathtofoo.db') # Windows
engine = create_engine('sqlite:///C:pathtofoo.db') # Windows
engine = create_engine(r'sqlite:///C:pathtofoo.db') # Windows alternative using raw string
engine = create_engine(r'sqlite:///C:pathtofoo.db') # Windows alternative using raw string