希望各位老师能够帮忙解答一下!一个自学的萌新,最近在看一篇公众号的实例上,关于利用 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.
不知道有没有老师能帮助一下我,万分感激。 (萌新一个,咱们这里发文没有编辑字体颜色和背景之类的东西吗?)
1
Kilerd 2018-02-15 18:32:08 +08:00
歪个楼,都 8102 年了,还用 web。py 啊
|
2
yanchaominhappy 2018-02-16 00:05:49 +08:00 via iPad 1
没有 movie 表,看的报错信息,学 flask 吧,教程也成熟,过来人惊艳
|
3
sylecn 2018-02-16 01:09:58 +08:00 via Android 1
>Connected to a transient in-memory database. Use ".open FILENAME" to reopen on a persistent database.
这个提示已经非常清楚了。你在命令行创建表的时候,连接的不是 MovieSite.db 数据库。所以 web 访问时找不到表。 |
4
shamashii 2018-02-20 19:58:17 +08:00
crossin 教室吧,我建议你先 game,web 那篇涉及到 sql,html,关键词绕来绕去对于新手很吃力
|