y3d*_*3di 2 python serialization jinja2 mongodb flask
我收到这个错误:
TypeError: datetime.datetime(2012, 2, 12, 0, 47, 6, 542000) is not JSON serializable
Run Code Online (Sandbox Code Playgroud)
当jinja试图解析这一行时:
var root_node_info = eval({{ nd|tojson|safe }});
Run Code Online (Sandbox Code Playgroud)
nd包含来自我的mongo数据库的bson对象.其中一个字段是日期时间对象.我怎样才能让烧瓶正确序列化?
这是我的mongokit模型(如果相关)
class Item(Document):
structure = {
"tldr": unicode,
"body": unicode,
"user": unicode,
"time_submitted": datetime.datetime,
"upvotes": int,
"downvotes": int,
"tags": [unicode]
}
validators = {
}
indexes = [
{'fields':['user']},
{'fields':['tags']}
]
use_dot_notation = True
required_fields = ['body', 'user', 'time_submitted']
default_values = {'time_submitted': datetime.datetime.utcnow}
def __repr__(self):
return '<item %r>' % (self._id)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4126 次 |
| 最近记录: |