0
我一直在关注这个基本的博客设置与Webpy:使用基本webpy博客的日期时间或时间戳
我所拥有的一切完全一样的,所以我不认为任何需要我在这里发布我的代码不过我使用PSQL,因此我有如下使我model.py一些变化,这就是:
import web
import datetime
db = web.database(dbn="postgres", db='basic_blog', user='my_name')
def get_posts():
return db.select('entries', order='id DESC')
def get_post(id):
try:
return db.select('entries', where='id=$id', vars=locals())[0]
except IndexError:
return None
def new_post(title, text):
db.insert('entries', title=title, content=text, posted_on=timestamp)
def del_post(id):
db.insert('entries', where='id=$id', vars=locals())
def update_post(id, title, text):
db.update('entries', where='id=$id', vars=locals(),
title=title, content=text)
当我创建的模式,我无法使用DATETIME,因为它似乎不要在psql中,所以我使用了TIMESTAMP,但是我不确定e如何让这个工作在model.py文件中,或者如果我需要导入datetime仍然。
当我尝试运行它是以上并进入/新在我的本地主机我得到这个错误信息:
global name 'timestamp' is not defined
我试图在PSQL模式变更的类型,只是“日期”但仍然有同样的问题,不知道还有什么要做。
非常感谢你! –
所以我现在得到这个错误,只要我点击提交后写一个测试职位在/新 列“posted_on”是时区类型的时间戳,但表达式是数值型的线1: ...试试(content,posted_on,title)VALUES('test',1450833444 ... ^提示:您将需要重写或转换表达式 Python \t /usr/local/lib/python2.7/site -packages/web/db.py in _db_execute,line 586 Web \t POST http:// localhost:8080/new –
'test'是我试图在那里提交的测试帖子,我不知道我需要重写什么表达式,这是否意味着在psql中的表达?我一直在阅读关于时间戳的文档,并从我的理解只是做'posted_on TIMESTAMP WITH TIMEZONE'应该工作(我认为) –