- 帖子
- 6
- 精华
- 0
- 积分
- 25
- 阅读权限
- 10
- 注册时间
- 2018-2-11
- 最后登录
- 2018-2-19
|
老师们好,又见面了。我肯定是建立数据库里的表了,但是只有建立的时候才能查到信息。关闭以后再查,用‘.tables’就什么也没有了,不知道为什么,是因为数据库保存路径的问题吗?
下面是微信平台上关于简单数据库那一部分的代码。
import web
urls = (
'/', 'index'
)
db = web.database(dbn='sqlite',db='MovieSite.db')
render = web.template.render('templates/')
class index:
def GET(self):
movies = db.select('movie')
return render.index(movies)
if __name__ == "__main__":
app = web.application(urls, globals())
app.run()
问题是我的网页总是报错:no such table:movie.
我确定自己已经建好表了,cmd相关情况如下:
D:\python>sqlite3
SQLite version 3.22.0 2018-01-22 18:45:57
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> .databases
main:
sqlite> create table movie(title,year,country,abstract);
sqlite> insert into movie
...> values ('阿甘正传', 1994, '美国', 'Life is like a box of chocolates.');
sqlite> insert into movie
...> values ('肖申克的救赎', 1994, '美国', 'Hope is a good thing.');
sqlite> select*from movie;
阿甘正传|1994|美国|Life is like a box of chocolates.
肖申克的救赎|1994|美国|Hope is a good thing.
sqlite> .tables
movie
sqlite> .quit
D:\python>python web1.py 127.0.0.1
http://127.0.0.1:8080/
ERR: SELECT * FROM movie
Traceback (most recent call last):
File "C:\Python3\lib\site-packages\web\application.py", line 257, in process
return self.handle()
File "C:\Python3\lib\site-packages\web\application.py", line 248, in handle
return self._delegate(fn, self.fvars, args)
File "C:\Python3\lib\site-packages\web\application.py", line 488, in _delegate
return handle_class(cls)
File "C:\Python3\lib\site-packages\web\application.py", line 466, in handle_class
return tocall(*args)
File "D:\python\web1.py", line 13, in GET
movies = db.select('movie')
File "C:\Python3\lib\site-packages\web\db.py", line 705, in select
return self.query(qout, processed=True)
File "C:\Python3\lib\site-packages\web\db.py", line 1058, in query
out = DB.query(self, *a, **kw)
File "C:\Python3\lib\site-packages\web\db.py", line 665, in query
self._db_execute(db_cursor, sql_query)
File "C:\Python3\lib\site-packages\web\db.py", line 596, in _db_execute
out = cur.execute(query, params)
sqlite3.OperationalError: no such table: movie
127.0.0.1:54375 - - [13/Feb/2018 23:59:13] "HTTP/1.1 GET /" - 500 Internal Server Error
|
|