我使用的是django feed框架。这是我的feeds.py中的内容:
def item_pubdate(self, item):
return item.posted这是我在models.py中的博客类中的内容:
posted = models.DateField(db_index=True, auto_now_add=True)我得到了这个属性错误:
'datetime.date' object has no attribute 'tzinfo'发布于 2011-08-28 16:44:46
有关def item_pubdate的要求,请参阅https://docs.djangoproject.com/en/dev/ref/contrib/syndication/。这是因为大多数提要格式在技术上都需要完整的时间戳作为发布日期。
您为提要定义的item_pubdate函数必须返回python datetime.datetime对象,而不是datetime.date对象。不同之处在于,除了日期信息之外,对象还可以包含特定的时间。
因此,您必须使用models.DateTimeField而不是models.DateField。
--
如果您坚持使用models.DateField,那么您可以让您的提要类进行转换:
from datetime import datetime, time
def item_pubdate(self, item):
return datetime.combine(item.posted, time())这应该会将您的日期转换为日期时间,以便contrib.syndication接受它。
发布于 2014-07-08 03:15:55
Django期望的是datetime而不是date。这里有一个隐藏它的方法:
import datetime
def item_pubdate(self, item):
return datetime.datetime(item.posted.year, item.posted.month, item.posted.day)https://stackoverflow.com/questions/7219599
复制相似问题