设为首页收藏本站

Crossin的编程教室

 找回密码
 立即加入
查看: 4619|回复: 0
打印 上一主题 下一主题

web.py SQlite相关问题

[复制链接]

3

主题

0

好友

25

积分

新手上路

Rank: 1

跳转到指定楼层
楼主
发表于 2018-2-14 08:06:25 |显示全部楼层 |倒序浏览
老师们好,又见面了。我肯定是建立数据库里的表了,但是只有建立的时候才能查到信息。关闭以后再查,用‘.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




回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即加入

QQ|手机版|Archiver|Crossin的编程教室 ( 苏ICP备15063769号  

GMT+8, 2024-5-3 04:49 , Processed in 0.019867 second(s), 22 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部