希望各位老师能够帮忙解答一下!一个自学的萌新,最近在看一篇公众号的实例上,关于利用 web.py 做一个关于电影数据的网站。引入了 SQlite 数据库,但是在运行代码的时候总是提示:
no such table:movie。
但是我绝对是建立了这个表了
以下是关于这个库具体建立表和数据的信息:
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
以下是 python 代码部分:
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()
以下是运行的报错情况:
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.
不知道有没有老师能帮助一下我,万分感激。 (萌新一个,咱们这里发文没有编辑字体颜色和背景之类的东西吗?)
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.