web.py 待办事项列表使用 sqlite 的 int() 无效文字
我正在关注这里的教程 http://webpy.org/docs/0.3/tutorial 然后查看在网上查找如何将待办事项列表部分与 sqlite 一起使用,并找到了这个 http://kzar.co.uk/blog/view/web.py-tutorial-sqlite
我无法通过此错误。我已经搜索过,但我找到的结果都没有对我有太多帮助。大多数人建议将括号中的引号去掉。
错误代码
<type 'exceptions.ValueError'> at /
invalid literal for int() with base 10: '19 02:39:09'
.py
import web
render = web.template.render('templates/')
db = web.database(dbn='sqlite', db='testdb')
urls = (
'/', 'index'
)
app = web.application(urls, globals())
class index:
def GET(self):
todos = db.select('todo')
return render.index(todos)
if __name__ == "__main__": app.run()
templates/index.html
$def with (todos)
<ul>
$for todo in todos:
<li id="t$todo.id">$todo.title</li>
</ul>
testbd
CREATE TABLE todo (id integer primary key, title text, created date, done boolean default 'f');
CREATE TRIGGER insert_todo_created after insert on todo
begin
update todo set created = datetime('now')
where rowid = new.rowid;
end;
对于 web.py sqlite 来说非常新
I was following the tutorial here http://webpy.org/docs/0.3/tutorial then looked around the webs to find out how to use the todo list part with sqlite and found this http://kzar.co.uk/blog/view/web.py-tutorial-sqlite
I cannot get passed this error. I have searched and none of the results i can find help me out too much. Most are suggesting to take the quotes out of the parentheses.
Error
<type 'exceptions.ValueError'> at /
invalid literal for int() with base 10: '19 02:39:09'
code.py
import web
render = web.template.render('templates/')
db = web.database(dbn='sqlite', db='testdb')
urls = (
'/', 'index'
)
app = web.application(urls, globals())
class index:
def GET(self):
todos = db.select('todo')
return render.index(todos)
if __name__ == "__main__": app.run()
templates/index.html
$def with (todos)
<ul>
$for todo in todos:
<li id="t$todo.id">$todo.title</li>
</ul>
testbd
CREATE TABLE todo (id integer primary key, title text, created date, done boolean default 'f');
CREATE TRIGGER insert_todo_created after insert on todo
begin
update todo set created = datetime('now')
where rowid = new.rowid;
end;
Very new to web.py sqlite
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在某个地方,使用参数
'19 02:39:09'
调用int()
。int()
无法处理冒号或空格。我建议调用
replace()
来删除空格和冒号,如下所示:希望这会有所帮助。
Somewhere,
int()
is being called with the argument'19 02:39:09'
.int()
can't handle colons or spaces.I would suggest calling
replace()
to get rid of the spaces and colons like this:Hope this helps.
只需将“创建”列的类型更改为时间戳:
日期格式为“YYYY-MM-DD”
时间戳-“YYYY-MM-DD HH:MM:SS”
此sql应该可以正常工作:
just change type of 'created' column to timestamp:
date format is "YYYY-MM-DD"
timestamp - "YYYY-MM-DD HH:MM:SS"
this sql should work fine: