Python 使用sqlite的web.py todo列表int()的文本无效
我在这里学习了教程,然后环顾了各个网站,了解了如何在sqlite中使用todo列表部分,并发现了以下内容 我无法通过这个错误。我已经搜索过了,没有一个结果对我有太大的帮助。大多数人建议去掉括号中的引号 错误 模板/index.htmlPython 使用sqlite的web.py todo列表int()的文本无效,python,sqlite,web.py,Python,Sqlite,Web.py,我在这里学习了教程,然后环顾了各个网站,了解了如何在sqlite中使用todo列表部分,并发现了以下内容 我无法通过这个错误。我已经搜索过了,没有一个结果对我有太大的帮助。大多数人建议去掉括号中的引号 错误 模板/index.html $def with (todos) <ul> $for todo in todos: <li id="t$todo.id">$todo.title</li> </ul> 对于web.py sqlite来说非
$def with (todos)
<ul>
$for todo in todos:
<li id="t$todo.id">$todo.title</li>
</ul>
对于web.py sqlite来说非常陌生在某个地方,int()
正在使用参数'19 02:39:09'
进行调用int()
无法处理冒号或空格
>>> int('19 02:39:09')
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
int('19 02:39:09')
ValueError: invalid literal for int() with base 10: '19 02:39:09'
>>> int(':')
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
int(':')
ValueError: invalid literal for int() with base 10: ':'
>>> int('19 02 39 09')
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
int('19 02 39 09')
ValueError: invalid literal for int() with base 10: '19 02 39 09'
>>> int('19023909')
19023909
>>>
希望这有帮助。只需将“已创建”列的类型更改为时间戳: 日期格式为“YYYY-MM-DD” 时间戳-“YYYY-MM-DD HH:MM:SS” 此sql应该可以正常工作:
CREATE TABLE todo (id integer primary key, title text, created timestamp, done boolean default 'f');
CREATE TRIGGER insert_todo_created after insert on todo
begin
update todo set created = datetime('now', 'localtime')
where rowid = new.rowid;
end;
这确实有所帮助。我不知道在本例中如何实际使用replace(),但现在我知道了问题的原因,我替换了sqlite使用的时间戳。从“现在”到“%j”。我必须给它更多的时间来找出正确的方法来解决它,使用您的解决方案,但这一点现在起作用了。非常感谢。不客气。:)真的没有“正确”的方法,我只是提供一个建议,如果你自己想不出的话。你可以自由使用最适合你的方法。
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;
>>> int('19 02:39:09')
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
int('19 02:39:09')
ValueError: invalid literal for int() with base 10: '19 02:39:09'
>>> int(':')
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
int(':')
ValueError: invalid literal for int() with base 10: ':'
>>> int('19 02 39 09')
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
int('19 02 39 09')
ValueError: invalid literal for int() with base 10: '19 02 39 09'
>>> int('19023909')
19023909
>>>
>>> date='19 02:39:09'
>>> date=date.replace(" ","")
>>> date
'1902:39:09'
>>> date=date.replace(":","")
>>> date
'19023909'
>>> int(date) ## It works now!
19023909
>>>
CREATE TABLE todo (id integer primary key, title text, created timestamp, done boolean default 'f');
CREATE TRIGGER insert_todo_created after insert on todo
begin
update todo set created = datetime('now', 'localtime')
where rowid = new.rowid;
end;