[windows] flask - sqlite3.OperationalError: unable to open database file
2015-11-16 23:19
946 查看
<span style="font-family: Arial, Helvetica, sans-serif;"># all the imports</span>
##from __future__ import with_statement import sqlite3 from flask import Flask, request, session, g, redirect,url_for, \ abort, render_template, flash from contextlib import closing import os # configuration <span style="color:#ff0000;">DATABASE = 'flaskr.db'</span> DEBUG = True SECRET_KEY = 'development key' USERNAME = 'admin' PASSWORD = '123' # create our little application app = Flask(__name__) app.config.from_object(__name__) for k, v in app.config.items(): print 'config[%s] = %s' % (k, v) def connect_db(): return sqlite3.connect(app.config.get('DATABASE')) def init_db(): with closing(connect_db()) as db: with app.open_resource('schema.sql') as f: db.cursor().executescript(f.read()) db.commit() if __name__ == '__main__': app.run()
from flaskr import init_db
init_db()
出现错误:sqlite3.OperationalError: unable to open database file
解决:
我的项目路径在E:\_PythonCode\flaskr下
在Python shell 上查看当前路径:
import os
os.getcwd()》'E:\\_PythonCode'
切换路径到项目路径下:
os.chdir('./flaskr')
此时路径为E:\_PythonCode\flaskr
from flaskr import init_db
init_db()
此时E:\_PythonCode\flaskr下会自动创建 flaskr.db 文件
相关文章推荐
- Python动态类型的学习---引用的理解
- Python3写爬虫(四)多线程实现数据爬取
- 垃圾邮件过滤器 python简单实现
- 下载并遍历 names.txt 文件,输出长度最长的回文人名。
- install and upgrade scrapy
- Scrapy的架构介绍
- Centos6 编译安装Python
- 如何使用 Flask 编写 Python Web API
- 使用Python生成Excel格式的图片
- 让Python文件也可以当bat文件运行
- [Python]推算数独
- Python中zip()函数用法举例
- Python中map()函数浅析
- Python将excel导入到mysql中
- Python在CAM软件Genesis2000中的应用
- 使用Shiboken为C++和Qt库创建Python绑定
- FREEBASIC 编译可被python调用的dll函数示例